

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

# 使用 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 群組。

此外，當您將 AWS 資源標籤新增至 Storage Lens 群組時，您可以啟用[屬性型存取控制 (ABAC)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)。ABAC 是一種根據屬性 (在此案例中為標籤) 定義許可的授權策略。您也可以使用條件在 IAM 政策中指定資源標籤，以[控制對 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) 和 建立 Amazon S3 Storage Lens 群組 適用於 Java 的 AWS SDK。

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

**建立 Storage Lens 群組**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)：// 開啟 Amazon 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 開發套件
<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 群組。此範例也會將兩個 AWS 資源標籤新增至 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.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 Storage Lens 群組的 S3 Storage Lens 範例組態](S3LensHelperFilesCLI.md#StorageLensGroupsHelperFilesCLI)。

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

**將 Storage Lens 群組連接至 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. 在 **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 管理主控台 ，並在 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)：// 開啟 Amazon 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 開發套件
<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>

您可以[將群組連接至 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 群組彙總中的 Storage Lens 群組納入您的儀表板組態之後，Storage Lens 群組資料最多可能需要 48 小時才會顯示在儀表板中。

儀表板組態更新後，任何新連接的 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) 和 來更新 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)。

# 使用 Storage Lens 群組管理 AWS 資源標籤
<a name="storage-lens-groups-manage-tags"></a>

每個 Amazon S3 Storage Lens 群組都會視為具有自己的 Amazon Resource Name (ARN) AWS 的資源。因此，當您設定 Storage Lens 群組時，您可以選擇性地將 AWS 資源標籤新增至群組。每個 Storage Lens 群組最多可新增 50 個標籤。若要建立具有標籤的 Storage Lens 群組，您必須擁有 `s3:CreateStorageLensGroup` 和 `s3:TagResource` 許可。

您可以使用 AWS 資源標籤，根據部門、業務單位或專案來分類資源。此做法在您擁有許多相同類型的資源時很有用。藉由套用標籤，您可以根據先前指派的標籤，快速識別特定的 Storage Lens 群組。您也可以使用標籤來追蹤和配置成本。

此外，當您將 AWS 資源標籤新增至 Storage Lens 群組時，您可以啟用[屬性型存取控制 (ABAC)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)。ABAC 是一種根據屬性 (在此案例中為標籤) 定義許可的授權策略。您也可以使用條件在 IAM 政策中指定資源標籤，以[控制對 AWS 資源的存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html#access_tags_control-resources)。

您可以編輯標籤索引鍵和值，也可以隨時從資源中移除標籤。此外，請留意下列限制：
+ 標籤索引鍵與標籤值皆區分大小寫。
+ 如果您新增的標籤具有與該資源上現有標籤相同的索引鍵，則新值會覆寫舊值。
+ 如果您刪除資源，也會刪除任何該資源所使用的標籤。
+ 請勿在 AWS 資源標籤中包含私有或敏感資料。
+ 不支援系統標籤 (具有以 `aws:` 開頭的標籤索引鍵)。
+ 每個標籤索引鍵的長度不可超過 128 個字元。每個標籤值的長度不可超過 256 個字元。

下列範例示範如何搭配 Storage Lens 群組使用 AWS 資源標籤。

**Topics**
+ [將 AWS 資源標籤新增至 Storage Lens 群組](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)

# 將 AWS 資源標籤新增至 Storage Lens 群組
<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>

**將 AWS 資源標籤新增至 Storage Lens 群組**

1. 登入 AWS 管理主控台 並開啟位於 https：//[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/) 的 Amazon 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 命令會將兩個資源標籤新增至名為 的現有 Storage Lens 群組`marketing-department`。若要使用此範例命令，請以您自己的資訊取代 `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 開發套件
<a name="storage-lens-groups-add-tags-sdk-java"></a>

下列 適用於 Java 的 AWS SDK 範例會將兩個 AWS 資源標籤新增至現有的 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 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) 和 更新 Storage Lens 群組標籤值 適用於 Java 的 AWS SDK。

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

**更新 Storage Lens 群組 AWS 的資源標籤**

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

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

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

1. 在 **AWS 資源標籤**底下，選取您要更新的標籤。

1. 使用與您要更新的鍵/值對相同的索引鍵，新增標籤值。選擇更新標籤值的核取記號圖示。
**注意**  
新增與現有標籤具有相同的索引鍵的標籤，將會覆寫先前的標籤值。

1. (選用) 如果您要新增標籤，請選擇**新增標籤**以新增項目。**Add tags (新增標籤)** 頁面隨即出現。

   您最多可以為 Storage Lens 群組新增 50 個 AWS 資源標籤。當您完成新增標籤的作業時，請選擇**儲存變更**。

1. (選用) 如果您要移除新增的項目，請在移除的標籤旁選擇**移除**。當您完成移除標籤的作業時，請選擇**儲存變更**。

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

下列範例 AWS CLI 命令會更新名為 之 Storage Lens 群組的兩個標籤值`marketing-department`。若要使用此範例命令，請以您自己的資訊取代 `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 開發套件
<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 管理主控台 ，並在 https：//[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/) 開啟 Amazon 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 開發套件
<a name="storage-lens-groups-delete-tags-sdk-java"></a>

下列 適用於 Java 的 AWS SDK 範例會從您在帳戶 中指定的 Storage Lens 群組 Amazon Resource Name (ARN) 刪除兩個 AWS 資源標籤`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.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 管理主控台 ，並在 https：//[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/) 開啟 Amazon 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 範例命令會列出名為 之 Storage Lens 群組的所有 Storage Lens 群組標籤值`marketing-department`。若要使用此範例命令，請以您自己的資訊取代 `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 開發套件
<a name="storage-lens-group-list-tags-sdk-java"></a>

下列 適用於 Java 的 AWS SDK 範例列出您指定之 Storage Lens 群組 Amazon Resource Name (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) 和 列出所有 Storage Lens 群組 適用於 Java 的 AWS SDK。

## 使用 S3 主控台
<a name="storage-lens-group-list-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 群組清單。

## 使用 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 開發套件
<a name="storage-lens-groups-list-sdk-java"></a>

下列 適用於 Java 的 AWS SDK 範例列出帳戶 的 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.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 管理主控台 ，並在 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)：// 開啟 Amazon 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 開發套件
<a name="view-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();
        }
    }
}
```

# 刪除 Storage Lens 群組
<a name="storage-lens-groups-delete"></a>

下列範例示範如何使用 Amazon S3 主控台 AWS Command Line Interface (AWS CLI) 和 刪除 Amazon S3 Storage Lens 群組 適用於 Java 的 AWS SDK。

## 使用 S3 主控台
<a name="delete-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. 選擇 **刪除**。**刪除 Storage Lens 群組**對話方塊隨即顯示。

1. 再次選擇**刪除**，可永久刪除 Storage Lens 群組。
**注意**  
Storage Lens 群組一旦刪除，就無法還原。

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

下列 AWS CLI 範例會刪除名為 的 Storage Lens 群組`marketing-department`。若要使用此範例命令，請以您自己的資訊取代 `user input placeholders`。

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

## 使用適用於 Java 的 AWS 開發套件
<a name="delete-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.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();
        }
    }
}
```