标记 Systems Manager 关联 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

标记 Systems Manager 关联

本节主题介绍如何在 State Manager 关联上使用标签。State Manager 是 Amazon Systems Manager 的组件。

使用标签创建关联

使用 Amazon CLI 创建关联时,可以将标签添加到 State Manager 关联中。不支持在使用 Systems Manager 控制台创建关联时将标签添加到关联。有关信息,请参阅 创建关联(命令行)

向现有关联添加标签

使用以下步骤通过命令行将标签添加到现有 State Manager 关联。

向现有关联添加标签 (Amazon CLI)

  1. 使用 Amazon CLI,运行以下命令以列出可以标记的关联。

    aws ssm list-associations

    记下要标记的关联的名称。

  2. 运行以下命令,以标记关联。将每个示例资源占位符替换为您自己的信息。

    aws ssm add-tags-to-resource \ --resource-type "Association" \ --resource-id "association-ID" \ --tags "Key=tag-key,Value=tag-value"

    如果成功,则命令没有输出。

  3. 运行以下命令以验证关联标签。

    aws ssm list-tags-for-resource --resource-type "Association" --resource-id "association-ID"

向现有关联添加标签 (Amazon Tools for PowerShell)

  1. 运行以下命令列出您可以标记的关联。

    Get-SSMAssociationList
  2. 运行以下命令标记一个参数。将每个示例资源占位符替换为您自己的信息。

    $tag = New-Object Amazon.SimpleSystemsManagement.Model.Tag
    $tag.Key = "tag-key"
    $tag.Value = "tag-value"
    Add-SSMResourceTag ` -ResourceType "Association" ` -ResourceId "association-ID" ` -Tag $tag ` -Force
  3. 运行以下命令以验证关联标签。

    Get-SSMResourceTag ` -ResourceType "Association" ` -ResourceId "association-ID"

从关联中删除标签

可以使用命令行从 State Manager 关联中删除标签。

从关联中删除标签(命令行)

  1. 使用您的首选命令行工具,运行以下命令,以列出您账户中的关联。

    Linux & macOS
    aws ssm list-associations
    Windows
    aws ssm list-associations
    PowerShell
    Get-SSMAssociationList

    记下要从中删除标签的关联的名称。

  2. 运行以下命令,以从关联中删除标签。将每个示例资源占位符替换为您自己的信息。

    Linux & macOS
    aws ssm remove-tags-from-resource \ --resource-type "Association" \ --resource-id "association-ID" \ --tag-key "tag-key"
    Windows
    aws ssm remove-tags-from-resource ^ --resource-type "Association" ^ --resource-id "association-ID" ^ --tag-key "tag-key"
    PowerShell
    Remove-SSMResourceTag -ResourceId "association-ID" -ResourceType "Association" -TagKey "tag-key

    如果成功,则命令没有输出。

  3. 运行以下命令以验证关联标签。

    Linux & macOS
    aws ssm list-tags-for-resource \ --resource-type "Association" \ --resource-id "association-ID"
    Windows
    aws ssm list-tags-for-resource ^ --resource-type "Association" ^ --resource-id "association-ID"
    PowerShell
    Get-SSMResourceTag ` -ResourceType "Association" ` -ResourceId "association-ID"