將 AWS 資源標籤新增至 Storage Lens 群組 - Amazon Simple Storage Service

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

將 AWS 資源標籤新增至 Storage Lens 群組

下列範例示範如何將 AWS 資源標籤新增至 Amazon S3 Storage Lens 群組。您可以使用 Amazon S3 主控台、AWS Command Line Interface (AWS CLI) 和 AWS SDK for Java 新增資源標籤。

將 AWS 資源標籤新增至 Storage Lens 群組
  1. 登入 AWS Management Console,並開啟位於 https://console.aws.amazon.com/s3/ 的 Amazon S3 主控台。

  2. 在左側導覽窗格中,選擇 Storage Lens 群組

  3. Storage Lens 群組底下,選擇您要更新的 Storage Lens 群組。

  4. AWS 資源標籤底下,選擇新增標籤

  5. 新增標籤頁面上,新增新的鍵/值對。

    注意

    新增與現有標籤具有相同的索引鍵的標籤,將會覆寫先前的標籤值。

  6. (選用) 若要新增多個標籤,請再次選擇新增標籤以繼續新增項目。您最多可以為 Storage Lens 群組新增最多 50 個 AWS 資源標籤。

  7. (選用) 如果您要移除新增的項目,請在移除的標籤旁選擇移除

  8. 選擇 Save changes (儲存變更)。

下列範例 AWS CLI 命令會將兩個資源標籤新增至名為 marketing-department 的現有 Storage Lens 群組。若要使用此範例命令,請以您自己的資訊取代 user input placeholders

aws s3control tag-resource --account-id 111122223333 \ --resource-arn arn:aws:s3:us-east-1:111122223333:storage-lens-group/marketing-department \ --region us-east-1 --tags Key=k1,Value=v1 Key=k2,Value=v2

下列 AWS SDK for Java 範例會將兩個 AWS 資源標籤新增至現有的 Storage Lens 群組。若要使用此範例,請以您自己的資訊取代 user input placeholders

package aws.example.s3control; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3control.S3ControlClient; import software.amazon.awssdk.services.s3control.model.Tag; import software.amazon.awssdk.services.s3control.model.TagResourceRequest; public class TagResource { public static void main(String[] args) { String resourceARN = "Resource_ARN"; String accountId = "111122223333"; try { Tag resourceTag1 = Tag.builder() .key("resource-tag-key-1") .value("resource-tag-value-1") .build(); Tag resourceTag2 = Tag.builder() .key("resource-tag-key-2") .value("resource-tag-value-2") .build(); TagResourceRequest tagResourceRequest = TagResourceRequest.builder() .resourceArn(resourceARN) .tags(resourceTag1, resourceTag2) .accountId(accountId) .build(); S3ControlClient s3ControlClient = S3ControlClient.builder() .region(Region.US_WEST_2) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); s3ControlClient.tagResource(tagResourceRequest); } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it and returned an error response. e.printStackTrace(); } catch (SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } } }