

# 使用 Storage Lens 组
<a name="storage-lens-group-tasks"></a>

Amazon S3 Storage Lens 存储统计管理工具组使用基于对象元数据的自定义筛选条件聚合指标。您可以使用前缀、后缀、对象标签、对象大小或对象龄期来分析和筛选 S3 Storage Lens 存储统计管理工具指标。使用 Amazon S3 Storage Lens 存储统计管理工具组，您还可以在 Amazon S3 桶内以及跨多个桶，对使用情况进行分类。因此，您将能够更好地了解和优化 S3 存储。

要开始可视化 Storage Lens 组的数据，必须先[将 Storage Lens 组附加到 S3 Storage Lens 存储统计管理工具控制面板](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-lens-groups-dashboard-console.html#storage-lens-groups-attach-dashboard-console)。如果您需要在控制面板中管理 Storage Lens 组，可以编辑控制面板配置。要查看您的账户下有哪些 Storage Lens 组，您可以将其列出。要查看哪些 Storage Lens 组已附加到控制面板，您可以随时查看控制面板中的 **Storage Lens 组**选项卡。要查看或更新现有 Storage Lens 组的范围，可以查看其详细信息。您还可以永久删除 Storage Lens 组。

要管理权限，您可以创建用户定义的 AWS 资源标签并将其添加到 Storage Lens 组。您可以使用 AWS 资源标签根据部门、业务线或项目对资源进行分类。如果您有许多相同类型的资源，这样做会非常有用。通过应用标签，您可以根据分配给特定 Storage Lens 组的标签快速识别该组。

此外，当您向 Storage Lens 组添加 AWS 资源标签时，将激活[基于属性的访问权限控制 (ABAC)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)。ABAC 是一种基于属性（在本文中，也就是标签）定义权限的授权策略。您还可以在 IAM policy 中使用指定资源标签的条件，从而[控制对 AWS 资源的访问](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html#access_tags_control-resources)。

**Topics**
+ [创建 Storage Lens 组](storage-lens-groups-create.md)
+ [将 S3 Storage Lens 组附加到控制面板或从控制面板移除](storage-lens-groups-dashboard-console.md)
+ [可视化 Storage Lens 组数据](storage-lens-groups-visualize.md)
+ [更新 Storage Lens 组](storage-lens-groups-update.md)
+ [使用 Storage Lens 组管理 AWS 资源标签](storage-lens-groups-manage-tags.md)
+ [列出所有 Storage Lens 组](storage-lens-groups-list.md)
+ [查看 Storage Lens 组详细信息](storage-lens-groups-view.md)
+ [删除 Storage Lens 组](storage-lens-groups-delete.md)

# 创建 Storage Lens 组
<a name="storage-lens-groups-create"></a>

以下示例演示如何使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 创建 Amazon S3 Storage Lens 存储统计管理工具组。

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

**创建 Storage Lens 组**

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

1. 在页面顶部的导航栏中，选择当前所显示 AWS 区域的名称。接下来，选择要切换到的区域。

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 选择**创建 Storage Lens 组**。

1. 在**常规**下，查看您的**主区域**，然后输入 **Storage Lens 组名称**。

1. 在**范围**下，选择要应用于 Storage Lens 组的筛选条件。要应用多个筛选条件，请选择您的筛选条件，然后选择 **AND** 或 **OR** 逻辑运算符。
   + 对于**前缀**筛选条件，请选择**前缀**，然后输入前缀字符串。要添加多个前缀，请选择**添加前缀**。要移除前缀，请选择要移除的前缀旁的**移除**。
   + 对于**对象标签**筛选条件，请选择**对象标签**，然后输入对象的键值对。然后选择**添加标签**。要移除标签，请选择要移除的标签旁的**移除**。
   + 对于**后缀**筛选条件，请选择**后缀**，然后输入后缀字符串。要添加多个后缀，请选择**添加后缀**。要移除后缀，请选择要移除的后缀旁的**移除**。
   + 对于**龄期**筛选条件，请以天为单位指定对象的龄期范围。选择**指定最小对象龄期**，然后输入最小对象龄期。然后，选择**指定最大对象龄期**并输入最大对象龄期。
   + 对于**大小**筛选条件，请指定对象大小范围和衡量单位。选择**指定最小对象大小**，然后输入最小对象大小。选择**指定最大对象大小**，然后输入最大对象大小。

1. （可选）对于 AWS 资源标签，请添加键值对，然后选择**添加标签**。

1. 选择**创建 Storage Lens 组**。

## 使用 AWS CLI
<a name="create-storage-lens-group-cli"></a>

以下示例 AWS CLI 命令将创建一个 Storage Lens 组。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control create-storage-lens-group --account-id 111122223333 \ 
--region us-east-1 --storage-lens-group=file://./marketing-department.json
```

以下示例 AWS CLI 命令将创建一个具有两个 AWS 资源标签的 Storage Lens 组。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control create-storage-lens-group --account-id 111122223333 \ 
--region us-east-1 --storage-lens-group=file://./marketing-department.json \
--tags Key=k1,Value=v1 Key=k2,Value=v2
```

有关示例 JSON 配置，请参阅 [Storage Lens 组配置](storage-lens-groups.md#storage-lens-groups-configuration)。

## 使用适用于 Java 的 AWS SDK
<a name="create-storage-lens-group-sdk-java"></a>

以下 适用于 Java 的 AWS SDK 示例将创建一个 Storage Lens 组。要使用此示例，请将 `user input placeholders` 替换为您自己的信息。

**Example – 创建包含单个筛选条件的 Storage Lens 组**  
以下示例将创建一个名为 `Marketing-Department` 的 Storage Lens 组。该组有一个对象龄期筛选条件，指定了 `30` 至 `90` 天的龄期范围。要使用此示例，请将 `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.CreateStorageLensGroupRequest;
import software.amazon.awssdk.services.s3control.model.MatchObjectAge;
import software.amazon.awssdk.services.s3control.model.StorageLensGroup;
import software.amazon.awssdk.services.s3control.model.StorageLensGroupFilter;
 
public class CreateStorageLensGroupWithObjectAge {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";
        
        try {
            StorageLensGroupFilter objectAgeFilter = StorageLensGroupFilter.builder()
                    .matchObjectAge(MatchObjectAge.builder()
                            .daysGreaterThan(30)
                            .daysLessThan(90)
                            .build())
                    .build();

            StorageLensGroup storageLensGroup = StorageLensGroup.builder()
                    .name(storageLensGroupName)
                    .filter(objectAgeFilter)
                    .build();

            CreateStorageLensGroupRequest createStorageLensGroupRequest = CreateStorageLensGroupRequest.builder()
                    .storageLensGroup(storageLensGroup)
                    .accountId(accountId).build();

            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            s3ControlClient.createStorageLensGroup(createStorageLensGroupRequest);
        } 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();
        }
    }
}
```

**Example – 使用 `AND` 运算符创建包含多个筛选条件的 Storage Lens 组**  
以下示例将创建一个名为 `Marketing-Department` 的 Storage Lens 组。该组使用 `AND` 运算符来指示对象必须匹配**所有**筛选条件。要使用此示例，请将 `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.CreateStorageLensGroupRequest;
import software.amazon.awssdk.services.s3control.model.MatchObjectAge;
import software.amazon.awssdk.services.s3control.model.MatchObjectSize;
import software.amazon.awssdk.services.s3control.model.S3Tag;
import software.amazon.awssdk.services.s3control.model.StorageLensGroup;
import software.amazon.awssdk.services.s3control.model.StorageLensGroupAndOperator;
import software.amazon.awssdk.services.s3control.model.StorageLensGroupFilter;


public class CreateStorageLensGroupWithAndFilter {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";

        try {
            // Create object tags.
            S3Tag tag1 = S3Tag.builder()
                    .key("object-tag-key-1")
                    .value("object-tag-value-1")
                    .build();
            S3Tag tag2 = S3Tag.builder()
                    .key("object-tag-key-2")
                    .value("object-tag-value-2")
                    .build();

            StorageLensGroupAndOperator andOperator = StorageLensGroupAndOperator.builder()
                    .matchAnyPrefix("prefix-1", "prefix-2", "prefix-3/sub-prefix-1")
                    .matchAnySuffix(".png", ".gif", ".jpg")
                    .matchAnyTag(tag1, tag2)
                    .matchObjectAge(MatchObjectAge.builder()
                            .daysGreaterThan(30)
                            .daysLessThan(90).build())
                    .matchObjectSize(MatchObjectSize.builder()
                            .bytesGreaterThan(1000L)
                            .bytesLessThan(6000L).build())
                    .build();

            StorageLensGroupFilter andFilter = StorageLensGroupFilter.builder()
                    .and(andOperator)
                    .build();

            StorageLensGroup storageLensGroup = StorageLensGroup.builder()
                    .name(storageLensGroupName)
                    .filter(andFilter)
                    .build();

            CreateStorageLensGroupRequest createStorageLensGroupRequest = CreateStorageLensGroupRequest.builder()
                    .storageLensGroup(storageLensGroup)
                    .accountId(accountId).build();

            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            s3ControlClient.createStorageLensGroup(createStorageLensGroupRequest);
        } 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();
        }
    }
}
```

**Example – 使用 `OR` 运算符创建包含多个筛选条件的 Storage Lens 组**  
以下示例将创建一个名为 `Marketing-Department` 的 Storage Lens 组。该组使用 `OR` 运算符来应用前缀筛选条件（`prefix-1`、`prefix-2`、`prefix3/sub-prefix-1`）或对象大小筛选条件（大小范围在 `1000` 字节至 `6000` 字节之间）。要使用此示例，请将 `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.CreateStorageLensGroupRequest;
import software.amazon.awssdk.services.s3control.model.MatchObjectSize;
import software.amazon.awssdk.services.s3control.model.StorageLensGroup;
import software.amazon.awssdk.services.s3control.model.StorageLensGroupFilter;
import software.amazon.awssdk.services.s3control.model.StorageLensGroupOrOperator;

public class CreateStorageLensGroupWithOrFilter {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";

        try {
            StorageLensGroupOrOperator orOperator = StorageLensGroupOrOperator.builder()
                    .matchAnyPrefix("prefix-1", "prefix-2", "prefix-3/sub-prefix-1")
                    .matchObjectSize(MatchObjectSize.builder()
                            .bytesGreaterThan(1000L)
                            .bytesLessThan(6000L)
                            .build())
                    .build();

            StorageLensGroupFilter orFilter = StorageLensGroupFilter.builder()
                    .or(orOperator)
                    .build();

            StorageLensGroup storageLensGroup = StorageLensGroup.builder()
                    .name(storageLensGroupName)
                    .filter(orFilter)
                    .build();

            CreateStorageLensGroupRequest createStorageLensGroupRequest = CreateStorageLensGroupRequest.builder()
                    .storageLensGroup(storageLensGroup)
                    .accountId(accountId).build();

            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            s3ControlClient.createStorageLensGroup(createStorageLensGroupRequest);
        } 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();
        }
    }
}
```

**Example – 使用单个筛选条件和两个 AWS 资源标签创建 Storage Lens 组**  
以下示例将创建一个名为 `Marketing-Department` 的 Storage Lens 组，该组具有后缀筛选条件。此示例还向 Storage Lens 组添加了两个 AWS 资源标签。要使用此示例，请将 `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.CreateStorageLensGroupRequest;
import software.amazon.awssdk.services.s3control.model.StorageLensGroup;
import software.amazon.awssdk.services.s3control.model.StorageLensGroupFilter;
import software.amazon.awssdk.services.s3control.model.Tag;

public class CreateStorageLensGroupWithResourceTags {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";

        try {
            // Create AWS resource tags.
            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();

            StorageLensGroupFilter suffixFilter = StorageLensGroupFilter.builder()
                    .matchAnySuffix(".png", ".gif", ".jpg")
                    .build();

            StorageLensGroup storageLensGroup = StorageLensGroup.builder()
                    .name(storageLensGroupName)
                    .filter(suffixFilter)
                    .build();

            CreateStorageLensGroupRequest createStorageLensGroupRequest = CreateStorageLensGroupRequest.builder()
                    .storageLensGroup(storageLensGroup)
                    .tags(resourceTag1, resourceTag2)
                    .accountId(accountId).build();

            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            s3ControlClient.createStorageLensGroup(createStorageLensGroupRequest);
        } 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();
        }
    }
}
```

有关示例 JSON 配置，请参阅 [Storage Lens 组配置](storage-lens-groups.md#storage-lens-groups-configuration)。

# 将 S3 Storage Lens 组附加到控制面板或从控制面板移除
<a name="storage-lens-groups-dashboard-console"></a>

在 Amazon S3 Storage Lens 存储统计管理工具中升级到高级级别后，您可以将 [Storage Lens 组](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-lens-groups-overview.html)附加到控制面板。如果您有多个 Storage Lens 组，则可以根据需要包括或排除组。

您的 Storage Lens 组必须位于控制面板账户中指定的主区域内。将 Storage Lens 组附加到控制面板后，您将在 48 小时内在指标导出中收到新增的 Storage Lens 组聚合数据。

**注意**  
如果要查看 Storage Lens 组的聚合指标，则必须将其附加到 Storage Lens 控制面板。有关 Storage Lens 组 JSON 配置文件的示例，请参阅 [JSON 格式的 S3 Storage Lens 存储统计管理工具示例配置（带 Storage Lens 组）](S3LensHelperFilesCLI.md#StorageLensGroupsHelperFilesCLI)。

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

**将 Storage Lens 组附加到 Storage Lens 控制面板**

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

1. 在左侧导航窗格中，在 **Storage Lens** 下选择**控制面板**。

1. 选择要将 Storage Lens 组附加到的 Storage Lens 控制面板的选项按钮。

1. 选择**编辑**。

1. 在 **Metrics selection**（指标选择）下方，请选择 **Advanced metrics and recommendations**（高级指标和建议）。

1. 选择 **Storage Lens 组聚合**。
**注意**  
默认情况下，还会选中**高级指标**。但是，您也可以取消选中此设置，因为聚合 Storage Lens 组数据并非必须。

1. 向下滚动到 **Storage Lens 组聚合**，然后指定要在数据聚合中包括或排除的一个或多个 Storage Lens 组。您可以使用以下筛选条件选项：
   + 如果要包括某些 Storage Lens 组，请选择**包括 Storage Lens 组**。在**要包括的 Storage Lens 组**下，选择您的 Storage Lens 组。
   + 如果要包括所有 Storage Lens 组，请选择**包括此账户中主区域中的所有 Storage Lens 组**。
   + 如果要排除某些 Storage Lens 组，请选择**排除 Storage Lens 组**。在**要排除的 Storage Lens 组**下，选择要排除的 Storage Lens 组。

1. 选择**保存更改**。如果您正确配置了 Storage Lens 组，则将在 48 小时内在控制面板中看到新增的 Storage Lens 组聚合数据。

**从 S3 Storage Lens 存储统计管理工具控制面板移除 Storage Lens 组**

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

1. 在左侧导航窗格中，在 **Storage Lens** 下选择**控制面板**。

1. 选择要从中移除 Storage Lens 组的 Storage Lens 控制面板的选项按钮。

1. 选择**查看控制面板配置**。

1. 选择**编辑**。

1. 向下滚动到**指标选择**部分。

1. 在 **Storage Lens 组聚合**下，选择要移除的 Storage Lens 组旁的 **X**。这将移除 Storage Lens 组。

   如果您在控制面板中包括了所有 Storage Lens 组，请清除**包括此账户中主区域中的所有 Storage Lens 组**旁的复选框。

1. 选择**保存更改**。
**注意**  
最多需要等待 48 小时，控制面板才会反映配置更新。

## 使用适用于 Java 的 AWS SDK
<a name="StorageLensGroupsConfigurationJava"></a>

**Example – 将所有 Storage Lens 组附加到控制面板**  
以下 Java 版 SDK 示例将账户 *111122223333* 中的所有 Storage Lens 组附加到 *DashBoardConfigurationId* 控制面板：  

```
package aws.example.s3control;


import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3control.AWSS3Control;
import com.amazonaws.services.s3control.AWSS3ControlClient;
import com.amazonaws.services.s3control.model.BucketLevel;
import com.amazonaws.services.s3control.model.PutStorageLensConfigurationRequest;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3control.model.AccountLevel;
import com.amazonaws.services.s3control.model.StorageLensConfiguration;
import com.amazonaws.services.s3control.model.StorageLensGroupLevel;

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

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

        try {
            StorageLensGroupLevel storageLensGroupLevel = new StorageLensGroupLevel();

            AccountLevel accountLevel = new AccountLevel()
                    .withBucketLevel(new BucketLevel())
                    .withStorageLensGroupLevel(storageLensGroupLevel);

            StorageLensConfiguration configuration = new StorageLensConfiguration()
                    .withId(configurationId)
                    .withAccountLevel(accountLevel)
                    .withIsEnabled(true);

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

            s3ControlClient.putStorageLensConfiguration(new PutStorageLensConfigurationRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
                    .withStorageLensConfiguration(configuration)
            );
        } 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();
        }
    }
}
```

**Example – 将两个 Storage Lens 组附加到控制面板**  
以下适用于 Java 的 AWS SDK 示例将两个 Storage Lens 组（*StorageLensGroupName1* 和 *StorageLensGroupName2*）附加到 *ExampleDashboardConfigurationId* 控制面板。  

```
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.AccountLevel;
import com.amazonaws.services.s3control.model.BucketLevel;
import com.amazonaws.services.s3control.model.PutStorageLensConfigurationRequest;
import com.amazonaws.services.s3control.model.StorageLensConfiguration;
import com.amazonaws.services.s3control.model.StorageLensGroupLevel;
import com.amazonaws.services.s3control.model.StorageLensGroupLevelSelectionCriteria;

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

public class CreateDashboardWith2StorageLensGroups {
    public static void main(String[] args) {
        String configurationId = "ExampleDashboardConfigurationId";
        String storageLensGroupName1 = "StorageLensGroupName1";
        String storageLensGroupName2 = "StorageLensGroupName2";
        String sourceAccountId = "111122223333";

        try {
            StorageLensGroupLevelSelectionCriteria selectionCriteria = new StorageLensGroupLevelSelectionCriteria()
                    .withInclude(
                            "arn:aws:s3:" + US_WEST_2.getName() + ":" + sourceAccountId + ":storage-lens-group/" + storageLensGroupName1,
                            "arn:aws:s3:" + US_WEST_2.getName() + ":" + sourceAccountId + ":storage-lens-group/" + storageLensGroupName2);

            System.out.println(selectionCriteria);
            StorageLensGroupLevel storageLensGroupLevel = new StorageLensGroupLevel()
                    .withSelectionCriteria(selectionCriteria);

            AccountLevel accountLevel = new AccountLevel()
                    .withBucketLevel(new BucketLevel())
                    .withStorageLensGroupLevel(storageLensGroupLevel);

            StorageLensConfiguration configuration = new StorageLensConfiguration()
                    .withId(configurationId)
                    .withAccountLevel(accountLevel)
                    .withIsEnabled(true);

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

            s3ControlClient.putStorageLensConfiguration(new PutStorageLensConfigurationRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
                    .withStorageLensConfiguration(configuration)
            );
        } 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();
        }
    }
}
```

**Example – 附加除排除项之外的所有 Storage Lens 组**  
以下 Java 版 SDK 示例将所有 Storage Lens 组附加到 *ExampleDashboardConfigurationId* 控制面板，但不包括指定的两个组（*StorageLensGroupName1* 和 *StorageLensGroupName2*）：  

```
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.AccountLevel;
import com.amazonaws.services.s3control.model.BucketLevel;
import com.amazonaws.services.s3control.model.PutStorageLensConfigurationRequest;
import com.amazonaws.services.s3control.model.StorageLensConfiguration;
import com.amazonaws.services.s3control.model.StorageLensGroupLevel;
import com.amazonaws.services.s3control.model.StorageLensGroupLevelSelectionCriteria;

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

public class CreateDashboardWith2StorageLensGroupsExcluded {
    public static void main(String[] args) {
        String configurationId = "ExampleDashboardConfigurationId";
        String storageLensGroupName1 = "StorageLensGroupName1";
        String storageLensGroupName2 = "StorageLensGroupName2";
        String sourceAccountId = "111122223333";

        try {
            StorageLensGroupLevelSelectionCriteria selectionCriteria = new StorageLensGroupLevelSelectionCriteria()
                    .withInclude(
                            "arn:aws:s3:" + US_WEST_2.getName() + ":" + sourceAccountId + ":storage-lens-group/" + storageLensGroupName1,
                            "arn:aws:s3:" + US_WEST_2.getName() + ":" + sourceAccountId + ":storage-lens-group/" + storageLensGroupName2);

            System.out.println(selectionCriteria);
            StorageLensGroupLevel storageLensGroupLevel = new StorageLensGroupLevel()
                    .withSelectionCriteria(selectionCriteria);

            AccountLevel accountLevel = new AccountLevel()
                    .withBucketLevel(new BucketLevel())
                    .withStorageLensGroupLevel(storageLensGroupLevel);

            StorageLensConfiguration configuration = new StorageLensConfiguration()
                    .withId(configurationId)
                    .withAccountLevel(accountLevel)
                    .withIsEnabled(true);

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

            s3ControlClient.putStorageLensConfiguration(new PutStorageLensConfigurationRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
                    .withStorageLensConfiguration(configuration)
            );
        } 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();
        }
    }
}
```

# 可视化 Storage Lens 组数据
<a name="storage-lens-groups-visualize"></a>

通过[将 Storage Lens 组附加到 Amazon S3 Storage Lens 存储统计管理工具控制面板](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-lens-groups-dashboard-console.html#storage-lens-groups-attach-dashboard-console)，您可以将该组数据可视化。在控制面板配置中将 Storage Lens 组包含在 Storage Lens 组聚合中后，最长可能需要 48 小时才能在控制面板中显示 Storage Lens 组的数据。

更新控制面板配置后，任何新附加的 Storage Lens 组都将显示在 **Storage Lens 组**选项卡下的可用资源列表中。您还可以在**概览**选项卡中，通过按其它维度对数据进行切片，来进一步分析存储使用情况。例如，您可以选择**前 3 个**类别下列出的项目之一，然后选择**分析依据**，按另一个维度对数据进行切片。不能应用与筛选条件本身相同的维度。

**注意**  
您不能将 Storage Lens 组筛选条件与前缀筛选条件一起应用，反之亦然。您也无法使用前缀筛选条件进一步分析 Storage Lens 组。

您可以使用 Amazon S3 Storage Lens 存储统计管理工具控制面板中的 **Storage Lens 组**选项卡，为附加到控制面板的 Storage Lens 组自定义数据可视化。您可以可视化附加到控制面板的某些 Storage Lens 组的数据，也可以将所有组的数据可视化。

在 S3 Storage Lens 存储统计管理工具控制面板中可视化 Storage Lens 组数据时，请注意以下几点：
+ S3 Storage Lens 存储统计管理工具聚合了所有匹配的 Storage Lens 组下某个对象的使用情况指标。因此，如果某个对象与两个或更多 Storage Lens 组的筛选条件相匹配，则在整个存储使用情况中，您会看到同一对象的重复计数。
+ 对象必须与您在 Storage Lens 组中包含的筛选条件相匹配。如果没有对象与您在 Storage Lens 组中包含的筛选条件相匹配，则不会生成任何指标。要确定是否有任何未分配的对象，请在控制面板中查看账户级别和桶级别的对象总数。

# 更新 Storage Lens 组
<a name="storage-lens-groups-update"></a>

以下示例演示如何更新 Amazon S3 Storage Lens 存储统计管理工具组。您可以使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 更新 Storage Lens 组。

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

**更新 Storage Lens 组**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，选择要更新的 Storage Lens 组。

1. 在**范围**下，选择**编辑**。

1. 在**范围**页面上，选择要应用于 Storage Lens 组的筛选条件。要应用多个筛选条件，请选择您的筛选条件，然后选择 **AND** 或 **OR** 逻辑运算符。
   + 对于**前缀**筛选条件，请选择**前缀**，然后输入前缀字符串。要添加多个前缀，请选择**添加前缀**。要移除前缀，请选择要移除的前缀旁的**移除**。
   + 对于**对象标签**筛选条件，请输入对象的键值对。然后选择**添加标签**。要移除标签，请选择要移除的标签旁的**移除**。
   + 对于**后缀**筛选条件，请选择**后缀**，然后输入后缀字符串。要添加多个后缀，请选择**添加后缀**。要移除后缀，请选择要移除的后缀旁的**移除**。
   + 对于**龄期**筛选条件，请以天为单位指定对象的龄期范围。选择**指定最小对象龄期**，然后输入最小对象龄期。对于**指定最大对象龄期**，请输入最大对象龄期。
   + 对于**大小**筛选条件，请指定对象大小范围和衡量单位。选择**指定最小对象大小**，然后输入最小对象大小。对于**指定最大对象大小**，请输入最大对象大小。

1. 选择**保存更改**。将显示 Storage Lens 组的详细信息页面。

1. （可选）如果要添加新的 AWS 资源标签，请滚动到 **AWS 资源标签**部分，然后选择**添加标签**。此时将显示**添加标签**页面。

   添加新的键值对，然后选择**保存更改**。将显示 Storage Lens 组的详细信息页面。

1. （可选）如果要移除现有 AWS 资源标签，请滚动到 **AWS 资源标签**部分，然后选择资源标签。然后选择 **Delete**(删除)。将出现**删除 AWS 标签**对话框。

   再次选择**删除**可永久删除 AWS 资源标签。
**注意**  
永久删除 AWS 资源标签后，该标签将无法还原。

## 使用 AWS CLI
<a name="update-storage-lens-group-cli"></a>

以下 AWS CLI 示例命令将返回名为 `marketing-department` 的 Storage Lens 组的配置详细信息。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。



```
aws s3control get-storage-lens-group --account-id 111122223333 \ 
--region us-east-1 --name marketing-department
```

以下 AWS CLI 示例将更新 Storage Lens 组。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control update-storage-lens-group --account-id 111122223333 \ 
--region us-east-1 --storage-lens-group=file://./marketing-department.json
```

有关示例 JSON 配置，请参阅 [Storage Lens 组配置](storage-lens-groups.md#storage-lens-groups-configuration)。

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

以下 适用于 Java 的 AWS SDK 示例将返回账户 `111122223333` 中 `Marketing-Department` 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.GetStorageLensGroupRequest;
import software.amazon.awssdk.services.s3control.model.GetStorageLensGroupResponse;

public class GetStorageLensGroup {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";

        try {
            GetStorageLensGroupRequest getRequest = GetStorageLensGroupRequest.builder()
                    .name(storageLensGroupName)
                    .accountId(accountId).build();
            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            GetStorageLensGroupResponse response = s3ControlClient.getStorageLensGroup(getRequest);
            System.out.println(response);
        } 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();
        }
    }
}
```

以下示例将更新账户 `111122223333` 中名为 `Marketing-Department` 的 Storage Lens 组。此示例将更新控制面板范围，使其包含与以下任何后缀匹配的对象：`.png`、`.gif`、`.jpg` 或 `.jpeg`。要使用此示例，请将 `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.StorageLensGroup;
import software.amazon.awssdk.services.s3control.model.StorageLensGroupFilter;
import software.amazon.awssdk.services.s3control.model.UpdateStorageLensGroupRequest;

public class UpdateStorageLensGroup {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";

        try {
            // Create updated filter.
            StorageLensGroupFilter suffixFilter = StorageLensGroupFilter.builder()
                    .matchAnySuffix(".png", ".gif", ".jpg", ".jpeg")
                    .build();

            StorageLensGroup storageLensGroup = StorageLensGroup.builder()
                    .name(storageLensGroupName)
                    .filter(suffixFilter)
                    .build();

            UpdateStorageLensGroupRequest updateStorageLensGroupRequest = UpdateStorageLensGroupRequest.builder()
                    .name(storageLensGroupName)
                    .storageLensGroup(storageLensGroup)
                    .accountId(accountId)
                    .build();

            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            s3ControlClient.updateStorageLensGroup(updateStorageLensGroupRequest);
        } 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();
        }
    }
}
```

有关示例 JSON 配置，请参阅 [Storage Lens 组配置](storage-lens-groups.md#storage-lens-groups-configuration)。

# 使用 Storage Lens 组管理 AWS 资源标签
<a name="storage-lens-groups-manage-tags"></a>

每个 Amazon S3 Storage Lens 存储统计管理工具组都视为一个 AWS 资源，具有自己的 Amazon 资源名称 (ARN)。因此，在配置 Storage Lens 组时，可以选择向该组添加 AWS 资源标签。最多可以为每个 Storage Lens 组添加 50 个标签。要创建带标签的 Storage Lens 组，您必须拥有 `s3:CreateStorageLensGroup` 和 `s3:TagResource` 权限。

您可以使用 AWS 资源标签根据部门、业务线或项目对资源进行分类。如果您有许多相同类型的资源，这样做会非常有用。通过应用标签，您可以根据分配给特定 Storage Lens 组的标签快速识别该组。您还可以使用标签对成本进行跟踪和分配。

此外，当您向 Storage Lens 组添加 AWS 资源标签时，将激活[基于属性的访问权限控制 (ABAC)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)。ABAC 是一种基于属性（在本文中，也就是标签）定义权限的授权策略。您还可以在 IAM policy 中使用指定资源标签的条件，从而[控制对 AWS 资源的访问](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html#access_tags_control-resources)。

您可以修改标签的键和值，还可以随时删除资源的标签。此外，请注意以下限制：
+ 标签键和标签值区分大小写。
+ 如果您添加的标签的值与该实例上现有标签的值相同，新的值就会覆盖旧值。
+ 如果删除资源，资源的所有标签也会被删除。
+ 不要在 AWS 资源标签中包含隐私或敏感数据。
+ 不支持系统标签（标签键以 `aws:` 开头）。
+ 每个标签键的长度不能超过 128 个字符。每个标签值的长度不能超过 256 个字符。

以下示例演示如何将 AWS 资源标签与 Storage Lens 组配合使用。

**Topics**
+ [向 Storage Lens 组添加 AWS 资源标签](storage-lens-groups-add-tags.md)
+ [更新 Storage Lens 组标签值](storage-lens-groups-update-tags.md)
+ [从 Storage Lens 组删除 AWS 资源标签](storage-lens-groups-delete-tags.md)
+ [列出 Storage Lens 组标签](storage-lens-groups-list-tags.md)

# 向 Storage Lens 组添加 AWS 资源标签
<a name="storage-lens-groups-add-tags"></a>

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

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

**向 Storage Lens 组添加 AWS 资源标签**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，选择要更新的 Storage Lens 组。

1. 在 **AWS 资源标签**下，选择**添加标签**。

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

1. （可选）要添加多个新标签，请再次选择**添加标签**以继续添加新条目。您最多可以将 50 个 AWS 资源标签添加到 Storage Lens 组。

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

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

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

以下示例 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
```

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

以下 适用于 Java 的 AWS SDK 示例将向现有 Storage Lens 组添加两个 AWS 资源标签。要使用此示例，请将 `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();
        }
    }
}
```

# 更新 Storage Lens 组标签值
<a name="storage-lens-groups-update-tags"></a>

以下示例演示如何使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 更新 Storage Lens 组标签值。

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

**更新 Storage Lens 组的 AWS 资源标签**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，选择要更新的 Storage Lens 组。

1. 在 **AWS 资源标签**下，选择要更新的标签。

1. 使用与要更新的键值对相同的键添加新标签值。选择对勾图标以更新标签值。
**注意**  
如果添加的新标签与现有标签具有相同的键，则将覆盖之前的标签值。

1. （可选）如果要添加新标签，请选择**添加标签**以添加新条目。此时将显示**添加标签**页面。

   最多可以为 Storage Lens 组添加 50 个 AWS 资源标签。添加完新标签后，选择**保存更改**。

1. （可选）如果要移除新添加的条目，请选择要移除的标签旁的**移除**。完成移除标签后，选择**保存更改**。

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

以下示例 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=v3 Key=k2,Value=v4
```

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

以下 适用于 Java 的 AWS 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();
        }
    }
}
```

# 从 Storage Lens 组删除 AWS 资源标签
<a name="storage-lens-groups-delete-tags"></a>

以下示例演示如何从 Storage Lens 组删除 AWS 资源标签。您可以使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 删除标签。

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

**从 Storage Lens 组删除 AWS 资源标签**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，选择要更新的 Storage Lens 组。

1. 在 **AWS 资源标签**下，选择要删除的键值对。

1. 选择**删除**。将出现**删除 AWS 资源标签**对话框。
**注意**  
如果使用标签控制访问，则继续执行此操作可能会影响相关资源。永久删除标签后，该标签将无法还原。

1. 选择**删除**，永久性删除该键值对。

## 使用 AWS CLI
<a name="storage-lens-groups-delete-tags-cli"></a>

以下 AWS CLI 命令将从现有 Storage Lens 组中删除两个 AWS 资源标签：要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control untag-resource --account-id 111122223333 \
--resource-arn arn:aws:s3:us-east-1:111122223333:storage-lens-group/Marketing-Department \
--region us-east-1 --tag-keys k1 k2
```

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

以下 适用于 Java 的 AWS SDK 示例将从账户 `111122223333` 中具有您所指定的 Amazon 资源名称 (ARN) 的 Storage Lens 组中，删除两个 AWS 资源标签。要使用此示例，请将 `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.UntagResourceRequest;

public class UntagResource {
    public static void main(String[] args) {
        String resourceARN = "Resource_ARN";
        String accountId = "111122223333";

        try {
            String tagKey1 = "resource-tag-key-1";
            String tagKey2 = "resource-tag-key-2";
            UntagResourceRequest untagResourceRequest = UntagResourceRequest.builder()
                    .resourceArn(resourceARN)
                    .tagKeys(tagKey1, tagKey2)
                    .accountId(accountId)
                    .build();
            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            s3ControlClient.untagResource(untagResourceRequest);
        } 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();
        }
    }
}
```

# 列出 Storage Lens 组标签
<a name="storage-lens-groups-list-tags"></a>

以下示例演示如何列出与 Storage Lens 组关联的 AWS 资源标签。您可以使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 列出标签。

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

**查看 Storage Lens 组的标签和标签值列表**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，选择您感兴趣的 Storage Lens 组。

1. 向下滚动到 **AWS 资源标签**部分。所有添加到您的 Storage Lens 组的用户定义的 AWS 资源标签及其标签值都将列出。

## 使用 AWS CLI
<a name="storage-lens-group-list-tags-cli"></a>

以下 AWS CLI 示例命令将列出名为 `marketing-department` 的 Storage Lens 组的所有 Storage Lens 组标签值。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control list-tags-for-resource --account-id 111122223333 \
--resource-arn arn:aws:s3:us-east-1:111122223333:storage-lens-group/marketing-department \
--region us-east-1
```

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

以下 适用于 Java 的 AWS SDK 示例将为您指定的 Storage Lens 组 Amazon 资源名称 (ARN) 列出 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.ListTagsForResourceRequest;
import software.amazon.awssdk.services.s3control.model.ListTagsForResourceResponse;

public class ListTagsForResource {
    public static void main(String[] args) {
        String resourceARN = "Resource_ARN";
        String accountId = "111122223333";

        try {
            ListTagsForResourceRequest listTagsForResourceRequest = ListTagsForResourceRequest.builder()
                    .resourceArn(resourceARN)
                    .accountId(accountId)
                    .build();
            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            ListTagsForResourceResponse response = s3ControlClient.listTagsForResource(listTagsForResourceRequest);
            System.out.println(response);
        } 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();
        }
    }
}
```

# 列出所有 Storage Lens 组
<a name="storage-lens-groups-list"></a>

以下示例演示如何列出 AWS 账户和主区域中的所有 Amazon S3 Storage Lens 存储统计管理工具组。这些示例显示了如何使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 列出所有 Storage Lens 组。

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

**列出账户和主区域中的所有 Storage Lens 组**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，将显示您账户中的 Storage Lens 组列表。

## 使用 AWS CLI
<a name="storage-lens-groups-list-cli"></a>

以下 AWS CLI 示例将列出您账户的所有 Storage Lens 组。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control list-storage-lens-groups --account-id 111122223333 \
--region us-east-1
```

## 使用适用于 Java 的 AWS SDK
<a name="storage-lens-groups-list-sdk-java"></a>

以下 适用于 Java 的 AWS SDK 示例将列出账户 `111122223333` 的 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.ListStorageLensGroupsRequest;
import software.amazon.awssdk.services.s3control.model.ListStorageLensGroupsResponse;

public class ListStorageLensGroups {
    public static void main(String[] args) {
        String accountId = "111122223333";

        try {
            ListStorageLensGroupsRequest listStorageLensGroupsRequest = ListStorageLensGroupsRequest.builder()
                    .accountId(accountId)
                    .build();
            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            ListStorageLensGroupsResponse response = s3ControlClient.listStorageLensGroups(listStorageLensGroupsRequest);
            System.out.println(response);
        } 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();
        }
    }
}
```

# 查看 Storage Lens 组详细信息
<a name="storage-lens-groups-view"></a>

以下示例演示如何查看 Amazon S3 Storage Lens 存储统计管理工具组配置详细信息。您可以使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 查看这些详细信息。

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



**查看 Storage Lens 组配置详细信息**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，选择您感兴趣的 Storage Lens 组旁的选项按钮。

1. 请选择**查看详细信息**。现在，您可以查看 Storage Lens 组的详细信息。

## 使用 AWS CLI
<a name="view-storage-lens-group-cli"></a>

以下 AWS CLI 示例将返回 Storage Lens 组的配置详细信息。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control get-storage-lens-group --account-id 111122223333 \ 
--region us-east-1 --name marketing-department
```

## 使用适用于 Java 的 AWS SDK
<a name="view-storage-lens-group-sdk-java"></a>

以下 适用于 Java 的 AWS SDK 示例将返回账户 `111122223333` 中名为 `Marketing-Department` 的 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.GetStorageLensGroupRequest;
import software.amazon.awssdk.services.s3control.model.GetStorageLensGroupResponse;

public class GetStorageLensGroup {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";

        try {
            GetStorageLensGroupRequest getRequest = GetStorageLensGroupRequest.builder()
                    .name(storageLensGroupName)
                    .accountId(accountId).build();
            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            GetStorageLensGroupResponse response = s3ControlClient.getStorageLensGroup(getRequest);
            System.out.println(response);
        } 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();
        }
    }
}
```

# 删除 Storage Lens 组
<a name="storage-lens-groups-delete"></a>

以下示例演示如何使用 Amazon S3 控制台、AWS Command Line Interface (AWS CLI) 和 适用于 Java 的 AWS SDK 删除 Amazon S3 Storage Lens 存储统计管理工具组。

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

**删除 Storage Lens 组**

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

1. 在左侧导航窗格中，选择 **Storage Lens 组**。

1. 在 **Storage Lens 组**下，选择要删除的 Storage Lens 组旁的选项按钮。

1. 选择**删除**。将显示**删除 Storage Lens 组**对话框。

1. 再次选择**删除**即可永久删除 Storage Lens 组。
**注意**  
Storage Lens 组在删除后无法还原。

## 使用 AWS CLI
<a name="delete-storage-lens-group-cli"></a>

以下 AWS CLI 示例将删除名为 `marketing-department` 的 Storage Lens 组。要使用此示例命令，请将 `user input placeholders` 替换为您自己的信息。

```
aws s3control delete-storage-lens-group --account-id 111122223333 \ 
--region us-east-1 --name marketing-department
```

## 使用适用于 Java 的 AWS SDK
<a name="delete-storage-lens-group-sdk-java"></a>

以下 适用于 Java 的 AWS SDK 示例将删除账户 `111122223333` 中名为 `Marketing-Department` 的 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.DeleteStorageLensGroupRequest;

public class DeleteStorageLensGroup {
    public static void main(String[] args) {
        String storageLensGroupName = "Marketing-Department";
        String accountId = "111122223333";

        try {
            DeleteStorageLensGroupRequest deleteStorageLensGroupRequest = DeleteStorageLensGroupRequest.builder()
                    .name(storageLensGroupName)
                    .accountId(accountId).build();
            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();
            s3ControlClient.deleteStorageLensGroup(deleteStorageLensGroupRequest);
        } 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();
        }
    }
}
```