向 Storage Lens 组添加 Amazon 资源标签
以下示例演示如何将 Amazon 资源标签添加到 Amazon S3 Storage Lens 存储统计管理工具组。您可以使用 Amazon S3 控制台、Amazon Command Line Interface(Amazon CLI)和 Amazon SDK for Java 添加资源标签。
向 Storage Lens 组添加 Amazon 资源标签
登录到 Amazon Web Services Management Console,然后通过以下网址打开 Amazon S3 控制台:https://console.aws.amazon.com/s3/
。 -
在左侧导航窗格中,选择 Storage Lens 组。
-
在 Storage Lens 组下,选择要更新的 Storage Lens 组。
-
在 Amazon 资源标签下,选择添加标签。
-
在添加标签页面上,添加新的键值对。
注意
如果添加的新标签与现有标签具有相同的键,则将覆盖之前的标签值。
-
(可选)要添加多个新标签,请再次选择添加标签以继续添加新条目。您最多可以将 50 个 Amazon 资源标签添加到 Storage Lens 组。
-
(可选)如果要移除新添加的条目,请选择要移除的标签旁的移除。
-
选择 Save changes(保存更改)。
以下示例 Amazon CLI 命令将向名为
的现有 Storage Lens 组添加两个资源标签。要使用此示例命令,请将 marketing-department
替换为您自己的信息。user input
placeholders
aws s3control tag-resource --account-id
111122223333
\ --resource-arn arn:aws:s3:us-east-1
:111122223333
:storage-lens-group/marketing-department
\ --regionus-east-1
--tags Key=k1
,Value=v1
Key=k2
,Value=v2
以下 Amazon SDK for Java 示例将向现有 Storage Lens 组添加两个 Amazon 资源标签。要使用此示例,请将
替换为您自己的信息。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(); } } }