

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

下列範例示範如何更新 Amazon S3 Storage Lens 群組。您可以使用 Amazon S3 主控台、 AWS Command Line Interface (AWS CLI) 和 來更新 Storage Lens 群組 適用於 Java 的 AWS SDK。

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

**更新 Storage Lens 群組**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)：// 開啟 Amazon S3 主控台。

1. 在左側導覽窗格中，選擇 **Storage Lens 群組**。

1. 在 **Storage Lens 群組**底下，選擇您要更新的 Storage Lens 群組。

1. 在**範圍**底下，選擇**編輯**。

1. 在**範圍**頁面上，選取要套用至 Storage Lens 群組的篩選條件。若要套用多個篩選條件，請選取篩選條件，然後選擇 **AND** 或 **OR** 邏輯運算子。
   + 針對**字首**篩選條件，選取**字首**，然後輸入字首字串。若要新增多個字首，請選擇**新增字首**。若要移除字首，請選擇要移除的字首旁的**移除**。
   + 針對**物件標籤**篩選條件，輸入物件的鍵/值對。然後，選擇**新增標籤**。若要移除標籤，請選擇要移除的標籤旁的**移除**。
   + 針對**尾碼**篩選條件，選取**尾碼**，然後輸入尾碼字串。若要新增多個尾碼，請選擇**新增尾碼**。若要移除尾碼，請選擇要移除的尾碼旁的**移除**。
   + 針對**存留期**篩選條件，指定物件存留期範圍 (天數)。選擇**指定最短物件存留期**，然後輸入最短的物件存留期。針對**指定最長物件存留期**，輸入最長的物件存留期。
   + 針對**大小**篩選條件，指定物件大小範圍和測量單位。選擇**指定最小物件大小**，然後輸入最小的物件大小。針對**指定最大物件大小**，輸入最大的物件大小。

1. 選擇**儲存變更**。Storage Lens 群組的詳細資訊頁面隨即出現。

1. （選用） 如果您要新增 AWS 資源標籤，請捲動至**AWS 資源標籤**區段，然後選擇**新增標籤**。**Add tags (新增標籤)** 頁面隨即出現。

   新增鍵/值對，然後選擇**儲存變更**。Storage Lens 群組的詳細資訊頁面隨即出現。

1. （選用） 如果您想要移除現有的 AWS 資源標籤，請捲動至**AWS 資源標籤**區段，然後選取資源標籤。再選擇 **Delete** (刪除)。**刪除 AWS 標籤**對話方塊隨即出現。

   再次選擇**刪除**，可永久刪除 AWS 資源標籤。
**注意**  
永久刪除 AWS 資源標籤後，就無法還原。

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

下列 AWS CLI 範例命令會傳回名為 之 Storage Lens 群組的組態詳細資訊`marketing-department`。若要使用此範例命令，請以您自己的資訊取代 `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 開發套件
<a name="update-storage-lens-group-sdk-java"></a>

下列 適用於 Java 的 AWS SDK 範例會傳回帳戶 中 `Marketing-Department` Storage Lens 群組的組態詳細資訊`111122223333`。若要使用此範例，請以您自己的資訊取代 `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)。