

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

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

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

**更新 Storage Lens 组**

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

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

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

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

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

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

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

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

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

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

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

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



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

以下 Amazon 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 的 Amazon SDK
<a name="update-storage-lens-group-sdk-java"></a>

以下 适用于 Java 的 Amazon 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)。