

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

# 建立 Amazon S3 Storage Lens 儀表板
<a name="storage_lens_creating_dashboard"></a>

您可以建立其他 S3 Storage Lens 自訂儀表板，這些儀表板可以範圍限定在帳戶中的特定 AWS Organizations AWS 區域 或 儲存貯體中的組織。

**注意**  
對儀表板組態的任何更新最多可能需要 48 小時才能正確顯示或視覺化。

## 使用 S3 主控台
<a name="storage_lens_console_creating"></a>

使用下列步驟在 Amazon S3 主控台上建立 Amazon S3 Storage Lens 儀表板。

**步驟 1：設定一般設定**

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

1. 在頁面頂端的導覽列中，選擇目前顯示的名稱 AWS 區域。接下來，選擇您想要切換到的區域。

1. 在左導覽窗格的 **S3 Storage Lens** 下，選擇**儀表板**。

1. 選擇 **Create dashboard (建立儀表板)**。

1. 在 **Dashboard (儀表板)** 頁面的 **General (一般)** 區段中，執行以下動作：

   1. 檢視儀表板的**主要區域**。主要區域是存放此 Storage Lens 儀表板 AWS 區域 組態和指標的 。

   1. 輸入儀表板名稱。

      儀表板名稱必須少於 65 個字元，且不得包含特殊字元或空格。
**注意**  
建立儀表板後，您就無法變更此儀表板名稱。

   1. 選擇**啟用**以在儀表板中顯示更新的每日指標。

   1. （選用） 您可以選擇將**標籤**新增至儀表板。您可以使用標籤來管理儀表板的權限，並追蹤 S3 Storage Lens 的成本。如需詳細資訊，請參閱《*IAM 使用者指南*》中的 [使用標籤控制對 AWS 資源的存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html)，以及*AWS Billing 《 使用者指南*》中的[使用 AWS產生的標籤](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/aws-tags.html)。
**注意**  
您最多可為儀表板組態中新增 50 個標籤。

1. 選擇**下一步**以儲存變更並繼續。

**步驟 2：定義儀表板範圍**

1. 在**儀表板範圍**區段中，選擇您希望 S3 Storage Lens 在儀表板中包含或排除的區域和儲存貯體。

1. 選擇您希望 S3 Storage Lens 包含或排除的選取區域儲存貯體。您可以包含或排除儲存貯體，但不能同時包含和排除。當您建立組織層級儀表板時，此選項無法使用。
**注意**  
您可以包含或排除區域和儲存貯體。在組織中跨成員帳戶建立組織層級儀表板時，此選項會僅限於「區域」。
您最多可以選擇 50 個要包含或排除的儲存貯體。

1. 選擇**下一步**以儲存變更並繼續。

**步驟 3：選擇 Storage Lens 方案**

1. 在 **Storage Lens 層**區段中，選擇要為此儀表板彙總的功能層。

   1. 若要包含在儲存貯體層級彙總並可用於查詢 14 天的免費指標，請選擇**免費方案**。

   1. 若要啟用進階指標，請選擇**進階層**。這些選項包括字首或 Storage Lens 群組彙總、Amazon CloudWatch 發佈、擴充字首報告，以及內容建議。資料有 15 個月的時間可用於查詢。進階指標和建議會有額外的費用。如需詳細資訊，請參閱 [Simple Storage Service (Amazon S3) 定價](https://aws.amazon.com/s3/pricing/)。

      如需進階指標和免費指標的詳細資訊，請參閱 [指標選擇](storage_lens_basics_metrics_recommendations.md#storage_lens_basics_metrics_selection)。

1. 在**進階指標類別**下，選取您要啟用的指標類別：
   + **活動指標**
   + **Detailed status code metrics** (詳細的狀態碼指標)
   + **成本最佳化指標**
   + **資料保護指標**
   + **效能指標**

   若要預覽每個類別中包含哪些指標，請使用指標類別核取方塊清單下方的下拉式箭頭按鈕。如需指標類別的詳細資訊，請參閱 [指標類別](storage_lens_basics_metrics_recommendations.md#storage_lens_basics_metrics_types)。如需指標的完整清單，請參閱[Amazon S3 Storage Lens 指標詞彙表](storage_lens_metrics_glossary.md)。

1. 選擇或指定**字首分隔符號**，以區分每個字首內的層級。此值用來識別每個字首層級。Amazon S3 中的預設值是「`/`」字元，但您的儲存結構可能會使用其他分隔符號字元。

1. 選擇**下一步**以儲存變更並繼續。

**步驟 4：（選用） 選擇您的指標彙總**

1. **在其他指標彙總**下，選擇要彙總的指標：
   + 字首彙總
   + Storage Lens 群組彙總

1. 如果您已啟用**字首彙總**，請指定儀表板和**字首深度的最低字首閾值**。 ****然後，選擇**下一步**以儲存並繼續。
**注意**  
**字首深度**設定會決定深度 S3 Storage Lens 會分析物件字首的階層層級，上限為 10 個層級。**字首閾值**會指定字首在包含在 Storage Lens 指標之前，必須代表的總儲存量百分比下限。

1. 如果您已啟用 **Storage Lens 群組彙總**，請選擇下列其中一項：
   + **包含 Storage Lens 群組**
   + **排除 Storage Lens 群組**

1. 當您在彙總中包含 Storage Lens 群組時，您可以**包含主區域中的所有 Storage Lens 群組**，或指定要包含的 Storage Lens 群組。

1. 選擇**下一步**以儲存變更並繼續。

**步驟 5：（選用） 選擇您的指標匯出和發佈設定**

1. 在**指標發佈**下，如果您想要存取 **CloudWatch 儀表板中的 Storage Lens 指標，請選擇 CloudWatch 發佈**。 CloudWatch 
**注意**  
CloudWatch 中無法使用字首層級指標。

1. 在**指標匯出**下，選擇您要每日匯出的 Storage Lens 儀表板資料：
   + **預設指標報告**
   + **擴充字首指標報告**

1. （選用） 如果您選擇**預設指標報告**，請在**預設指標報告**設定中選擇儲存貯體類型。您可以將報告匯出至一般用途的 Amazon S3 儲存貯體 AWS或受管 S3 資料表儲存貯體。根據選取的儲存貯體類型，更新**一般用途儲存貯體目的地設定**或**資料表儲存貯體目的地設定**選項。
**注意**  
**預設指標報告**僅包含設定閾值內的字首，以及字首彙總設定中設定的深度。  
如果您選擇指定加密金鑰，則必須選擇 AWS KMS 金鑰 (SSE-KMS) 或 Amazon S3 受管金鑰 (SSE-S3)。如果您的目的地儲存貯體政策需要加密，您必須為指標匯出提供加密金鑰。如果沒有加密金鑰，匯出至 S3 失敗。如需詳細資訊，請參閱[使用 AWS KMS key 加密指標匯出](storage_lens_encrypt_permissions.md)。

1. （選用） 如果您選擇**展開字首指標報告**，請在**展開字首指標報告**設定中選擇儲存貯體類型。您可以將報告匯出至一般用途的 Amazon S3 儲存貯體或唯讀 S3 資料表儲存貯體。根據選取的儲存貯體類型，更新**一般用途儲存貯體目的地設定**或**資料表儲存貯體目的地設定**。
**注意**  
**展開字首指標報告**包含儀表板範圍中指定之所有所選儲存貯體中字首深度上限為 50 的所有字首。  
如果您選擇指定加密金鑰，則必須選擇 AWS KMS 金鑰 (SSE-KMS) 或 Amazon S3 受管金鑰 (SSE-S3)。如果您的目的地儲存貯體政策需要加密，您必須為指標匯出提供加密金鑰。如果沒有加密金鑰，匯出至 S3 失敗。如需詳細資訊，請參閱[使用 AWS KMS key 加密指標匯出](storage_lens_encrypt_permissions.md)。

1. 選擇**下一步**以儲存變更並繼續。

1. 檢閱**和建立**頁面上的所有內容。如果沒有其他變更，請選擇**下一步**以儲存變更並建立儀表板。

**步驟 6：檢閱儀表板組態並建立儀表板**

1. 在**一般**區段中，檢閱您的設定。選擇**編輯**以進行任何變更。

1. 在**儀表板範圍**區段中，檢閱您的設定。選擇**編輯**以進行任何變更。

1. 在 **Storage Lens 方案**區段中，檢閱您的設定。選擇**編輯**以進行任何變更。

1. 在**指標彙總**區段中，檢閱您的設定。選擇**編輯**以進行任何變更。

1. 在**指標匯出**區段中，檢閱您的設定。選擇**編輯**以進行任何變更。

1. 檢閱並確認所有儀表板組態設定後，請選擇**提交**以建立儀表板。

成功建立新的 Storage Lens 儀表板後，您可以檢視 Storage Lens 儀表板頁面下列出的新**儀表板**。

## 使用 AWS CLI
<a name="S3PutStorageLensConfigurationTagsCLI"></a>

**Example**  
下列範例命令會建立包含標籤的 Amazon S3 Storage Lens 組態。若要使用這些範例，請以您自己的資訊取代 `{{user input placeholders}}`。  

```
aws s3control put-storage-lens-configuration --account-id={{111122223333}} --config-id={{example-dashboard-configuration-id}} --region={{us-east-1}} --storage-lens-configuration={{file://./config.json}} --tags={{file://./tags.json}}
```

**Example**  
下列範例命令會建立不含標籤的 Amazon S3 Storage Lens 組態。若要使用這些範例，請以您自己的資訊取代 `{{user input placeholders}}`。  

```
aws s3control put-storage-lens-configuration --account-id={{222222222222}} --config-id={{your-configuration-id}} --region={{us-east-1}} --storage-lens-configuration={{file://./config.json}}
```

## 使用適用於 Java 的 AWS 開發套件
<a name="S3CreateandUpdateStorageLensConfigurationJava"></a>

**Example – 建立和更新 Amazon S3 Storage Lens 組態**  
下列範例會在適用於 Java 的 SDK 中建立和更新 Amazon S3 Storage Lens 組態：  

```
package aws.example.s3control;

import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.exception.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.AccountLevel;
import software.amazon.awssdk.services.s3control.model.ActivityMetrics;
import software.amazon.awssdk.services.s3control.model.AdvancedCostOptimizationMetrics;
import software.amazon.awssdk.services.s3control.model.AdvancedDataProtectionMetrics;
import software.amazon.awssdk.services.s3control.model.AdvancedPerformanceMetrics;
import software.amazon.awssdk.services.s3control.model.BucketLevel;
import software.amazon.awssdk.services.s3control.model.CloudWatchMetrics;
import software.amazon.awssdk.services.s3control.model.DetailedStatusCodesMetrics;
import software.amazon.awssdk.services.s3control.model.Format;
import software.amazon.awssdk.services.s3control.model.Include;
import software.amazon.awssdk.services.s3control.model.OutputSchemaVersion;
import software.amazon.awssdk.services.s3control.model.PrefixLevel;
import software.amazon.awssdk.services.s3control.model.PrefixLevelStorageMetrics;
import software.amazon.awssdk.services.s3control.model.PutStorageLensConfigurationRequest;
import software.amazon.awssdk.services.s3control.model.S3BucketDestination;
import software.amazon.awssdk.services.s3control.model.SSES3;
import software.amazon.awssdk.services.s3control.model.SelectionCriteria;
import software.amazon.awssdk.services.s3control.model.StorageLensAwsOrg;
import software.amazon.awssdk.services.s3control.model.StorageLensConfiguration;
import software.amazon.awssdk.services.s3control.model.StorageLensDataExport;
import software.amazon.awssdk.services.s3control.model.StorageLensDataExportEncryption;
import software.amazon.awssdk.services.s3control.model.StorageLensExpandedPrefixesDataExport;
import software.amazon.awssdk.services.s3control.model.StorageLensTableDestination;
import software.amazon.awssdk.services.s3control.model.StorageLensTag;

import java.util.Arrays;
import java.util.List;

public class CreateAndUpdateDashboard {

    public static void main(String[] args) {
        String configurationId = "{{ConfigurationId}}";
        String sourceAccountId = "{{111122223333}}";
        String exportAccountId = "{{Destination Account ID}}";
        String exportBucketArn = "arn:aws:s3:::{{destBucketName}}"; // The destination bucket for your metrics export must be in the same Region as your S3 Storage Lens configuration.
        String awsOrgARN = "arn:aws:organizations::{{123456789012}}:organization/{{o-abcdefgh}}";
        Format exportFormat = Format.CSV;

        try {
            SelectionCriteria selectionCriteria = SelectionCriteria.builder()
                    .delimiter("{{/}}")
                    .maxDepth({{5}})
                    .minStorageBytesPercentage({{10.0}})
                    .build();

            PrefixLevelStorageMetrics prefixStorageMetrics = PrefixLevelStorageMetrics.builder()
                    .isEnabled({{true}})
                    .selectionCriteria(selectionCriteria)
                    .build();

            BucketLevel bucketLevel = BucketLevel.builder()
                    .activityMetrics(ActivityMetrics.builder().isEnabled({{true}}).build())
                    .advancedCostOptimizationMetrics(AdvancedCostOptimizationMetrics.builder().isEnabled({{true}}).build())
                    .advancedDataProtectionMetrics(AdvancedDataProtectionMetrics.builder().isEnabled({{true}}).build())
                    .advancedPerformanceMetrics(AdvancedPerformanceMetrics.builder().isEnabled({{true}}).build())
                    .detailedStatusCodesMetrics(DetailedStatusCodesMetrics.builder().isEnabled({{true}}).build())
                    .prefixLevel(PrefixLevel.builder().storageMetrics(prefixStorageMetrics).build())
                    .build();

            AccountLevel accountLevel = AccountLevel.builder()
                    .activityMetrics(ActivityMetrics.builder().isEnabled({{true}}).build())
                    .advancedCostOptimizationMetrics(AdvancedCostOptimizationMetrics.builder().isEnabled({{true}}).build())
                    .advancedPerformanceMetrics(AdvancedPerformanceMetrics.builder().isEnabled({{true}}).build())
                    .advancedDataProtectionMetrics(AdvancedDataProtectionMetrics.builder().isEnabled({{true}}).build())
                    .detailedStatusCodesMetrics(DetailedStatusCodesMetrics.builder().isEnabled({{true}}).build())
                    .bucketLevel(bucketLevel)
                    .build();

            Include include = Include.builder()
                    .buckets(Arrays.asList("arn:aws:s3:::{{bucketName}}"))
                    .regions(Arrays.asList("{{us-west-2}}"))
                    .build();

            StorageLensDataExportEncryption exportEncryption = StorageLensDataExportEncryption.builder()
                    .sses3(SSES3.builder().build())
                    .build();

            S3BucketDestination s3BucketDestination = S3BucketDestination.builder()
                    .accountId(exportAccountId)
                    .arn(exportBucketArn)
                    .encryption(exportEncryption)
                    .format(exportFormat)
                    .outputSchemaVersion(OutputSchemaVersion.V_1)
                    .prefix("{{Prefix}}")
                    .build();

            StorageLensTableDestination s3TablesDestination = StorageLensTableDestination.builder()
                    .encryption(exportEncryption)
                    .isEnabled({{true}})
                    .build();

            CloudWatchMetrics cloudWatchMetrics = CloudWatchMetrics.builder()
                    .isEnabled({{true}})
                    .build();

            StorageLensDataExport dataExport = StorageLensDataExport.builder()
                    .cloudWatchMetrics(cloudWatchMetrics)
                    .s3BucketDestination(s3BucketDestination)
                    .storageLensTableDestination(s3TablesDestination)
                    .build();

            StorageLensAwsOrg awsOrg = StorageLensAwsOrg.builder()
                    .arn(awsOrgARN)
                    .build();

            StorageLensExpandedPrefixesDataExport expandedPrefixesDataExport = StorageLensExpandedPrefixesDataExport.builder()
                    .s3BucketDestination(s3BucketDestination)
                    .storageLensTableDestination(s3TablesDestination)
                    .build();

            StorageLensConfiguration configuration = StorageLensConfiguration.builder()
                    .id(configurationId)
                    .accountLevel(accountLevel)
                    .include(include)
                    .dataExport(dataExport)
                    .awsOrg(awsOrg)
                    .expandedPrefixesDataExport(expandedPrefixesDataExport)
                    .prefixDelimiter("{{/}}")
                    .isEnabled({{true}})
                    .build();

            List<StorageLensTag> tags = Arrays.asList(
                    StorageLensTag.builder().key("{{key-1}}").value("{{value-1}}").build(),
                    StorageLensTag.builder().key("{{key-2}}").value("{{value-2}}").build()
            );

            S3ControlClient s3ControlClient = S3ControlClient.builder()
                    .region(Region.{{US_WEST_2}})
                    .credentialsProvider(ProfileCredentialsProvider.create())
                    .build();

            s3ControlClient.putStorageLensConfiguration(PutStorageLensConfigurationRequest.builder()
                    .accountId(sourceAccountId)
                    .configId(configurationId)
                    .storageLensConfiguration(configuration)
                    .tags(tags)
                    .build()
            );

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

若要存取 S3 Storage Lens 群組或擴充字首，您必須升級儀表板才能使用進階層。需支付額外費用。如需免費和進階方案的詳細資訊，請參閱 [指標選擇](storage_lens_basics_metrics_recommendations.md#storage_lens_basics_metrics_selection)。如需關於 S3 Storage Lens 群組的詳細資訊，請參閱 [使用 S3 Storage Lens 群組來篩選和彙總指標](storage-lens-groups-overview.md)。