

# 将 Amazon 资源标签添加到 Storage Lens 存储统计管理工具控制面板
<a name="storage-lens-add-tags"></a>

以下示例演示如何将 Amazon 资源标签添加到 S3 Storage Lens 存储统计管理工具控制面板。您可以使用 Amazon S3 控制台、Amazon Command Line Interface (Amazon CLI) 和 适用于 Java 的 Amazon SDK 添加资源标签。

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

**将 Amazon 资源标签添加到 Storage Lens 存储统计管理工具控制面板**

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

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

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

1. 选择您要更新的 Storage Lens 存储统计管理工具控制面板的单选按钮。然后选择 **Edit**（编辑）。

1. 在**常规**下，选择**添加标签**。

1. 在**添加标签**页面上，添加新的键值对。
**注意**  
如果添加的新标签与现有标签具有相同的键，则将覆盖之前的标签值。

1. （可选）要添加多个新标签，请再次选择**添加标签**以继续添加新条目。最多可以将 50 个 Amazon 资源标签添加到 Storage Lens 存储统计管理工具控制面板。

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

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

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

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

```
aws s3control put-storage-lens-configuration-tagging --account-id={{222222222222}} --region={{us-east-1}} --config-id={{your-configuration-id}} --tags={{file://./tags.json}}
```

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

以下示例命令在适用于 Java 的 SDK 中将标签添加到 Amazon S3 Storage Lens 存储统计管理工具配置。要使用此示例，请将 `{{user input placeholders}}` 替换为您自己的信息。

**Example – 将标签添加到 S3 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();
        }
    }
}
```