

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 管理行为图的标签
<a name="graph-tags"></a>

标签是一个可选标签，您可以定义并分配给 AWS 资源，包括某些类型的 Detective 资源。标签可以帮助您以不同的方式识别、分类和管理资源，例如，按用途、所有者、环境或其他标准。例如，您可以使用标签来应用策略、分配成本、区分资源版本，或识别支持特定合规性要求或工作流的资源。

您可以为行为图分配标签。然后，您可以使用IAM策略中的标签值来管理对 Detective 中行为图函数的访问权限。请参阅 [基于 Detective 行为图标签的授权](security_iam_service-with-iam.md#security_iam_service-with-iam-tags)。

您也可以将标签用作费用报告工具。例如，要跟踪与安全相关的成本，您可以为 Detective 行为图、 AWS Security Hub CSPM 中心资源和 Amazon 探 GuardDuty 测器分配相同的标签。然后 AWS Cost Explorer，您可以在中搜索该标签以查看这些资源的成本的合并视图。

## 查看行为图的标签
<a name="graph-tags-list"></a>

您可以从**常规**页面管理行为图的标签。

------
#### [ Console ]

**要查看分配给行为图的标签列表**

1. 通过 [https://console.aws.amazon.com/detective/](https://console.aws.amazon.com/detective/) 打开 Amazon Detective 控制台。

1. 在导航窗格中的**设置**下，选择**常规**。

------
#### [ Detective API, AWS CLI ]

你可以使用 Detective API 或 the AWS Command Line Interface 来获取行为图的标签列表。

**要获取行为图的标签列表（DetectiveAPI， AWS CLI）**
+ D@@ **etectiveAPI：**使用该[https://docs.aws.amazon.com/detective/latest/APIReference/API_ListTagsForResource.html](https://docs.aws.amazon.com/detective/latest/APIReference/API_ListTagsForResource.html)操作。您必须提供您的ARN行为图表。
+ **AWS CLI：**在命令行处，运行 `list-tags-for-resource` 命令。

  ```
  aws detective list-tags-for-resource --resource-arn <behavior graph ARN>
  ```

  **示例**

  ```
  aws detective list-tags-for-resource --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
  ```

------

## 向行为图添加标签
<a name="graph-tags-add"></a>

------
#### [ Console ]

您可以在**常规**页面的标签列表中将标签值添加到行为图中。

**要向行为图添加标签**

1. 选择**添加新标签**。

1. 对于**键**，输入标签的名称。

1. 对于**值**，输入标签的值。

------
#### [ Detective API, AWS CLI ]

您可以使用 Detective API 或 AWS CLI ，将标签值添加到行为图中。

**向行为图添加标签（DetectiveAPI， AWS CLI）**
+ D@@ **etectiveAPI：**使用该[https://docs.aws.amazon.com/detective/latest/APIReference/API_TagResource.html](https://docs.aws.amazon.com/detective/latest/APIReference/API_TagResource.html)操作。您可以提供行为图ARN和要添加的标签值。
+ **AWS CLI**：在命令行处，运行 `tag-resource` 命令。

  ```
  aws-detective tag-resource --aws detective tag-resource --resource-arn <behavior graph ARN> --tags '{"TagName":"TagValue"}'
  ```

  **示例**

  ```
  aws detective tag-resource --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 --tags '{"Department":"Finance"}'
  ```

------

## 从行为图中移除标签
<a name="graph-tags-remove"></a>

------
#### [ Console ]

要从**常规**页面的列表中删除标签，请为该标签选择**删除**选项。

------
#### [ Detective API, AWS CLI ]

您可以使用 Detectiv AWS CLI e API 或从行为图中删除标签值。

**要从行为图中移除标签（DetectiveAPI， AWS CLI）**
+ D@@ **etectiveAPI：**使用该[https://docs.aws.amazon.com/detective/latest/APIReference/API_UntagResource.html](https://docs.aws.amazon.com/detective/latest/APIReference/API_UntagResource.html)操作。您可以提供行为图ARN以及要移除的标签的名称。
+ **AWS CLI**：在命令行处，运行 `untag-resource` 命令。

  ```
  aws detective untag-resource --resource-arn <behavior graph ARN> --tag-keys "TagName"
  ```

  **示例**

  ```
  aws detective untag-resource --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 --tag-keys "Department"
  ```

------