

# AWS Glue 中的标记 API
<a name="aws-glue-api-tags"></a>

## 数据类型
<a name="aws-glue-api-tags-objects"></a>
+ [Tag 结构](#aws-glue-api-tags-Tag)

## Tag 结构
<a name="aws-glue-api-tags-Tag"></a>

`Tag` 对象表示用户可分配给 AWS 资源的标签。每个标签都包含定义的一个键和一个可选值。

有关标签以及如何控制对 AWS Glue 中资源的访问的更多信息，请参阅开发人员指南中的 [AWS Glue 中的 AWS 标签](https://docs.aws.amazon.com/glue/latest/dg/monitor-tags.html)和[指定 AWS Glue 资源 ARN](https://docs.aws.amazon.com/glue/latest/dg/glue-specifying-resource-arns.html)。

**Fields**
+ `key` – UTF-8 字符串，长度不少于 1 个字节或超过 128 个字节。

  标签键。在对象上创建标签时需要这个键。键区分大小写，并且不得包含前缀 aws。
+ `value` – UTF-8 字符串，不超过 256 个字节。

  标签值。在对象上创建标签时，值是可选的。值区分大小写，并且不得包含前缀 aws。

## 操作
<a name="aws-glue-api-tags-actions"></a>
+ [TagResource 操作（Python：tag\_resource）](#aws-glue-api-tags-TagResource)
+ [UntagResource 操作（Python：untag\_resource）](#aws-glue-api-tags-UntagResource)
+ [GetTags 操作（Python：get\_tags）](#aws-glue-api-tags-GetTags)

## TagResource 操作（Python：tag\_resource）
<a name="aws-glue-api-tags-TagResource"></a>

为资源添加标签。标签是为 AWS 资源分配的标记。在 AWS Glue 中，您只能为特定资源添加标签。有关可添加标签的资源的信息，请参阅 [AWS Glue 中的 AWS 标签](https://docs.aws.amazon.com/glue/latest/dg/monitor-tags.html)。

除了调用标签相关的 API 的标记权限外，您还需要在连接上调用标记 API 的 `glue:GetConnection` 权限以及对数据库调用标记 API 的 `glue:GetDatabase` 权限。

**请求**
+ `ResourceArn` – *必填*：UTF-8 字符串，长度不少于 1 个字节或超过 10240 个字节，与 [Custom string pattern #50](aws-glue-api-common.md#regex_50) 匹配。

  要向其添加标签的 AWS Glue 资源的 ARN。有关 AWS Glue 资源 ARN 的更多信息，请参阅 [AWS Glue ARN 字符串模式](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-common.html#aws-glue-api-regex-aws-glue-arn-id)。
+ `TagsToAdd` – *必填*：键值对的映射数组，不超过 50 对。

  每个键都是一个 UTF-8 字符串，长度不少于 1 个字节或超过 128 个字节。

  每个值是一个 UTF-8 字符串，不超过 256 个字节。

  要添加到此资源的标签。

**响应**
+ *无响应参数。*

**错误**
+ `ResourceNotFoundException`

## UntagResource 操作（Python：untag\_resource）
<a name="aws-glue-api-tags-UntagResource"></a>

从集成资源中删除指定的标签。

**请求**
+ `ResourceArn` – *必填*：UTF-8 字符串，长度不少于 1 个字节或超过 10240 个字节，与 [Custom string pattern #50](aws-glue-api-common.md#regex_50) 匹配。

  集成资源的 Amazon 资源名称 (ARN)。
+ `TagsToRemove` – *必填*：UTF-8 字符串数组，不超过 50 个字符串。

  要从资源中删除的元数据标签列表。

**响应**
+ *无响应参数。*

**错误**
+ `ResourceNotFoundException`

## GetTags 操作（Python：get\_tags）
<a name="aws-glue-api-tags-GetTags"></a>

检索与资源关联的标签的列表。

**请求**
+ `ResourceArn` – *必填*：UTF-8 字符串，长度不少于 1 个字节或超过 10240 个字节，与 [Custom string pattern #50](aws-glue-api-common.md#regex_50) 匹配。

  要检索其标签的资源的 Amazon Resource Name（ARN）。

**响应**
+ `Tags` – 键值对的映射数组，不超过 50 对。

  每个键都是一个 UTF-8 字符串，长度不少于 1 个字节或超过 128 个字节。

  每个值是一个 UTF-8 字符串，不超过 256 个字节。

  请求的标签。

**错误**
+ `InvalidInputException`
+ `InternalServiceException`
+ `OperationTimeoutException`
+ `EntityNotFoundException`