更新 Storage Lens 组标签值
以下示例演示如何使用 Amazon S3 控制台、Amazon Command Line Interface (Amazon CLI) 和 适用于 Java 的 Amazon SDK 更新 Storage Lens 组标签值。
更新 Storage Lens 组的 Amazon 资源标签
登录到 Amazon Web Services Management Console,然后通过以下网址打开 Amazon S3 控制台:https://console.aws.amazon.com/s3/
。 -
在左侧导航窗格中,选择 Storage Lens 组。
-
在 Storage Lens 组下,选择要更新的 Storage Lens 组。
-
在 Amazon 资源标签下,选择要更新的标签。
-
使用与要更新的键值对相同的键添加新标签值。选择对勾图标以更新标签值。
注意
如果添加的新标签与现有标签具有相同的键,则将覆盖之前的标签值。
-
(可选)如果要添加新标签,请选择添加标签以添加新条目。此时将显示添加标签页面。
最多可以为 Storage Lens 组添加 50 个 Amazon 资源标签。添加完新标签后,选择保存更改。
-
(可选)如果要移除新添加的条目,请选择要移除的标签旁的移除。完成移除标签后,选择保存更改。
以下示例 Amazon CLI 命令将更新名为 的 Storage Lens 组的两个标签值。要使用此示例命令,请将 marketing-department 替换为您自己的信息。user input
placeholders
aws s3control tag-resource --account-id111122223333\ --resource-arn arn:aws:s3:us-east-1:111122223333:storage-lens-group/marketing-department\ --regionus-east-1--tags Key=k1,Value=v3Key=k2,Value=v4
以下 适用于 Java 的 Amazon SDK 示例将更新 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 UpdateTagsForResource { public static void main(String[] args) { String resourceARN = "Resource_ARN"; String accountId = "111122223333"; try { Tag updatedResourceTag1 = Tag.builder() .key("resource-tag-key-1") .value("resource-tag-updated-value-1") .build(); Tag updatedResourceTag2 = Tag.builder() .key("resource-tag-key-2") .value("resource-tag-updated-value-2") .build(); TagResourceRequest tagResourceRequest = TagResourceRequest.builder() .resourceArn(resourceARN) .tags(updatedResourceTag1,updatedResourceTag2) .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(); } } }