Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
标记自动化
本节主题介绍如何在自动化上使用标签。您最多可以向 Amazon Systems Manager 自动化添加五个标签。您可以在从控制台或命令行启动自动化时向自动化添加标签,或者在它们已使用命令行运行之后向自动化添加标签。
向自动化添加标签(控制台)
访问 https://console.aws.amazon.com/systems-manager/,打开 Amazon Systems Manager 控制台。
在左侧导航窗格中,选择自动化。
- 或者 -
如果首先打开 Amazon Systems Manager 主页,选择菜单图标 (
) 以打开导航窗格,然后选择自动化。
-
选择要运行的自动化运行手册。
-
选择 Execute automation(执行自动化)。
-
在标签部分中,选择编辑,然后添加一个或多个键值标签对。
-
选择 Save(保存)。
向自动化添加标签(命令行)
使用首选的命令行工具,运行以下命令以在自动化启动时向其添加标签。将每个示例资源占位符
替换为您自己的信息。
- Linux & macOS
-
aws ssm start-automation-execution \
--document-name DocumentName
\
--parameters ParametersRequiredByDocument
\
--tags "Key=ExampleKey
,Value=ExampleValue
"
- Windows
-
aws ssm start-automation-execution ^
--document-name DocumentName
^
--parameters ParametersRequiredByDocument
^
--tags "Key=ExampleKey
,Value=ExampleValue
"
- PowerShell
-
$exampleTag = New-Object Amazon.SimpleSystemsManagement.Model.Tag
$exampleTag.Key = "ExampleKey
"
$exampleTag.Value = "ExampleValue
"
Start-SSMAutomationExecution `
-DocumentName DocumentName
`
-Parameter ParametersRequiredByDocument
-Tag $exampleTag
-
您还可以使用首选的命令行工具在自动化运行后标记自动化。运行以下命令以向自动化添加标签。将每个示例资源占位符
替换为您自己的信息。
- Linux & macOS
-
aws ssm add-tags-to-resource \
--resource-type "Automation" \
--resource-id "automation-execution-id
" \
--tags "Key=ExampleKey
,Value=ExampleValue
"
- Windows
-
aws ssm add-tags-to-resource ^
--resource-type "Automation" ^
--resource-id "automation-execution-id
" ^
--tags "Key=ExampleKey
,Value=ExampleValue
"
- PowerShell
-
$exampleTag = New-Object Amazon.SimpleSystemsManagement.Model.Tag
$exampleTag.Key = "ExampleKey
"
$exampleTag.Value = "ExampleValue
"
Add-SSMResourceTag `
-ResourceType "Automation" `
-ResourceId "automation-execution-id
" `
-Tag $exampleTag `
-Force
如果成功,则命令没有输出。
-
运行以下命令以验证自动化的标签。
- Linux & macOS
-
aws ssm list-tags-for-resource \
--resource-type "Automation" \
--resource-id "automation-execution-id
"
- Windows
-
aws ssm list-tags-for-resource ^
--resource-type "Automation" ^
--resource-id "automation-execution-id
"
- PowerShell
-
Get-SSMResourceTag `
-ResourceType "Automation" `
-ResourceId "automation-execution-id
"
从自动化中删除标签
您可以使用命令行工具从自动化中删除标签。
从自动化中删除标签(命令行)
-
使用首选的命令行工具,运行以下命令以从自动化中删除标签。将每个示例资源占位符
替换为您自己的信息。
- Linux & macOS
-
aws ssm remove-tags-from-resource \
--resource-type "Automation" \
--resource-id "automation-execution-id
" \
--tag-key "tag-key
"
- Windows
-
aws ssm remove-tags-from-resource ^
--resource-type "Automation" ^
--resource-id "automation-execution-id
" ^
--tag-key "tag-key
"
- PowerShell
-
Remove-SSMResourceTag `
-ResourceId "automation-execution-id
" `
-ResourceType "Automation" `
-TagKey "tag-key
" `
-Force
-
运行以下命令以验证自动化的标签。
- Linux & macOS
-
aws ssm list-tags-for-resource \
--resource-type "Automation" \
--resource-id "automation-execution-id
"
- Windows
-
aws ssm list-tags-for-resource ^
--resource-type "Automation" ^
--resource-id "automation-execution-id
"
- PowerShell
-
Get-SSMResourceTag `
-ResourceType "Automation" `
-ResourceId "automation-execution-id
"