

# 更新 Storage Lens 存储统计管理工具控制面板标签
<a name="storage-lens-update-tags"></a>

以下示例演示如何使用 Amazon S3 控制台、Amazon Command Line Interface（Amazon CLI）和适用于 Java 的 Amazon SDK 更新 Storage Lens 存储统计管理工具控制面板标签。

## 使用 S3 控制台
<a name="storage-lens-dashboard-update-tags-console"></a>

**更新 Storage Lens 存储统计管理工具控制面板的 Amazon 资源标签**

1. 登录到 Amazon Web Services 管理控制台，然后通过以下网址打开 Amazon S3 控制台：[https://console.aws.amazon.com/s3/](https://console.amazonaws.cn/s3/)。

1. 在左侧导航窗格中，导航到 **Storage Lens 存储统计管理工具**。

1. 选择**控制面板**。

1. 选择您要查看的 Storage Lens 存储统计管理工具控制面板配置的单选按钮。然后，选择**查看控制面板配置**。

1. 在**标签**下，查看与控制面板关联的标签。

1. （可选）如果要添加新标签，请选择**编辑**。然后选择**添加标签**。在**添加标签**页面上，添加新的键值对。
**注意**  
如果添加的新标签与现有标签具有相同的键，则将覆盖之前的标签值。

1. （可选）如果要移除新添加的条目，请选择要移除的标签旁的**移除**。

1. 选择**保存更改**。

## 使用 Amazon CLI
<a name="storage-lens-dashboard-update-tags-cli"></a>

**Example**  
以下示例命令添加或替换现有 Amazon S3 Storage Lens 存储统计管理工具控制面板配置上的标签。要使用这些示例，请将 `user input placeholders` 替换为您自己的信息。  

```
aws s3control put-storage-lens-configuration-tagging --account-id=111122223333 --config-id=example-dashboard-configuration-id --region=us-east-1 --config-id=your-configuration-id
```

## 使用适用于 Java 的 Amazon SDK
<a name="storage-lens-dashboard-update-tags-sdk-java"></a>

以下适用于 Java 的 Amazon SDK 示例更新现有 Storage Lens 存储统计管理工具控制面板上的 Amazon 资源标签。要使用此示例，请将 `user input placeholders` 替换为您自己的信息。

**Example – 更新现有 Storage Lens 存储统计管理工具控制面板配置上的标签**  

```
package aws.example.s3control;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3control.AWSS3Control;
import com.amazonaws.services.s3control.AWSS3ControlClient;
import com.amazonaws.services.s3control.model.PutStorageLensConfigurationTaggingRequest;
import com.amazonaws.services.s3control.model.StorageLensTag;

import java.util.Arrays;
import java.util.List;

import static com.amazonaws.regions.Regions.US_WEST_2;

public class PutDashboardTagging {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "111122223333";

        try {
            List<StorageLensTag> tags = Arrays.asList(
                    new StorageLensTag().withKey("key-1").withValue("value-1"),
                    new StorageLensTag().withKey("key-2").withValue("value-2")
            );

            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            s3ControlClient.putStorageLensConfigurationTagging(new PutStorageLensConfigurationTaggingRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
                    .withTags(tags)
            );
        } 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();
        }
    }
}
```