

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

# 在您的儀表板上連接或移除 S3 Storage Lens 群組
連接或移除 Storage Lens 群組

在 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 主控台


**將 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 開發套件


**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();
        }
    }
}
```