

# 管理 S3 访问权限管控的标签
<a name="access-grants-tagging"></a>

Amazon S3 Access Grants 中的标签与 Amazon S3 中的[对象标签](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-tagging.html)具有相似的特征。每个标签都是一个键-值对。您可以在 S3 Access Grants 中标记的资源是 S3 Access Grants [实例](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-instance.html)、[位置](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-location.html)和[授权](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-grant.html)。

**注意**  
S3 Access Grants 中的标记使用与对象标记不同的 API 操作。S3 访问权限管控使用 [https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_TagResource.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_TagResource.html)、[https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_UntagResource.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_UntagResource.html) 和 [https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_ListTagsForResource.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_ListTagsForResource.html) API 操作，其中资源可以是 S3 访问权限管控实例、已注册的位置或访问授权。

与[对象标签](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-tagging.html)类似，以下限制将适用：
+ 可以在创建新的 S3 Access Grants 资源时向其添加标签，也可以向现有资源添加标签。
+ 您最多可以将 10 个标签与一个资源关联。如果多个标签与同一资源关联，则它们必须具有唯一的标签键。
+ 标签键的长度最大可以为 128 个 Unicode 字符，标签值的长度最大可以为 256 个 Unicode 字符。标签在内部以 UTF-16 表示。采用 UTF-16 时，字符占用 1 或 2 个字符位置。
+ 键和值区分大小写。

有关标签限制的更多信息，请参阅《AWS Billing 用户指南》**中的[用户定义的标签限制](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/allocation-tag-restrictions.html)。

您可以使用 AWS Command Line Interface（AWS CLI）、Amazon S3 REST API 或 AWS SDK 在 S3 Access Grants 中标记资源。

## 使用 AWS CLI
<a name="access-grants-tagging-cli"></a>

要安装 AWS CLI，请参阅 *AWS Command Line Interface 用户指南*中的[安装 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

可以在创建 S3 Access Grants 资源时或之后为其添加标签。以下示例说明如何标记或取消标记 S3 Access Grants 实例。可以为已注册位置和访问授权执行类似的操作。

要使用以下示例命令，请将 `user input placeholders` 替换为您自己的信息。

**Example – 创建带标签的 S3 Access Grants 实例**  

```
aws s3control create-access-grants-instance \
 --account-id 111122223333 \
 --profile access-grants-profile \
 --region us-east-2 \
 --tags Key=tagKey1,Value=tagValue1
```
响应：  

```
 {
    "CreatedAt": "2023-10-25T01:09:46.719000+00:00",
    "AccessGrantsInstanceId": "default",
    "AccessGrantsInstanceArn": "arn:aws:s3:us-east-2:111122223333:access-grants/default"
}
```

**Example – 标记已创建的 S3 Access Grants 实例**  

```
aws s3control tag-resource \
--account-id 111122223333 \
--resource-arn "arn:aws:s3:us-east-2:111122223333:access-grants/default" \
--profile access-grants-profile \
--region us-east-2 \
--tags Key=tagKey2,Value=tagValue2
```

**Example – 列出 S3 Access Grants 实例的标签**  

```
aws s3control list-tags-for-resource \
--account-id 111122223333 \
--resource-arn "arn:aws:s3:us-east-2:111122223333:access-grants/default" \
--profile access-grants-profile \
--region us-east-2
```
响应：  

```
{
    "Tags": [
        {
            "Key": "tagKey1",
            "Value": "tagValue1"
        },
        {
            "Key": "tagKey2",
            "Value": "tagValue2"
        }
    ]
}
```

**Example – 取消标记 S3 Access Grants 实例**  

```
aws s3control untag-resource \
 --account-id 111122223333 \
 --resource-arn "arn:aws:s3:us-east-2:111122223333:access-grants/default" \
 --profile access-grants-profile \
 --region us-east-2 \
 --tag-keys "tagKey2"
```

## 使用 REST API
<a name="access-grants-tagging-rest-api"></a>

可以使用 Amazon S3 API 来标记、取消标记 S3 Access Grants 实例、已注册位置或访问授权，或列出这些项的标签。有关用于管理 S3 Access Grants 标签的 REST API 支持的信息，请参阅**《Amazon Simple Storage Service API 参考》中的以下部分：
+  [https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_TagResource.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_TagResource.html) 
+  [https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_UntagResource.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_UntagResource.html) 
+  [https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_ListTagsForResource.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_ListTagsForResource.html)