

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 管理 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 SDKs 來標記 S3 Access Grants 中的資源。 Amazon S3 

## 使用 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)