

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

# 透過主控台和 API 使用 Amazon S3 Storage Lens
<a name="S3LensExamples"></a>

Amazon S3 Storage Lens 是一種雲端儲存體分析功能，您可以用來了解整個組織使用物件儲存體的情況及其活動情形。您可以使用 S3 Storage Lens 指標產生摘要洞見，例如了解您在整個組織中擁有多少儲存體，或是成長速度最快的儲存貯體和字首有哪些。您也可以使用 S3 Storage Lens 指標，識別成本最佳化機會、實作資料保護和安全最佳實務，以及改善應用程式工作負載的效能。例如，您可以識別沒有 S3 生命週期規則的儲存貯體，這些規則可使超過 7 天未完成的分段上傳過期。您也可以識別未遵循資料保護最佳實務的儲存貯體，例如使用 S3 複寫或 S3 版本控制。S3 Storage Lens 也會分析指標，以提供內容相關建議，您可以用來最佳化儲存成本，並套用最佳實務保護您的資料。

S3 Storage Lens 會彙總您的指標，並在 Amazon S3 主控台 **Buckets** (儲存貯體) 頁面上的 **Account snapshot** (帳戶快照) 區段中顯示資訊。S3 Storage Lens 也提供互動式儀表板，您可以用來視覺化洞見和趨勢、標記極端值，以及接收最佳化儲存成本和套用資料保護最佳實務的建議。您的儀表板具有向下切入選項，可在組織、帳戶、 AWS 區域儲存類別、儲存貯體、字首或 Storage Lens 群組層級產生和視覺化洞見。您也可以將 CSV 或 Parquet 格式的每日指標報告傳送至一般用途 S3 儲存貯體，或直接將指標匯出至 AWS受管 S3 資料表儲存貯體。

**注意**  
Storage Lens 只會彙總 [S3 一般用途儲存貯](UsingBucket.md)體的指標。

以下區段包含建立、更新和檢視 S3 Storage Lens 組態的範例，以及執行與此功能相關操作的範例。如果您搭配 S3 Storage Lens 使用 AWS Organizations，這些範例也會涵蓋這些使用案例。在範例中，取代任何預留位置值。

**Topics**
+ [

# 建立 Amazon S3 Storage Lens 儀表板
](storage_lens_creating_dashboard.md)
+ [

# 更新 Amazon S3 Storage Lens 儀表板
](storage_lens_editing.md)
+ [

# 停用 Amazon S3 Storage Lens 儀表板
](storage_lens_disabling.md)
+ [

# 刪除 Amazon S3 Storage Lens 儀表板
](storage_lens_deleting.md)
+ [

# 列出 Amazon S3 Storage Lens 儀表板
](storage_lens_list_dashboard.md)
+ [

# 檢視 Amazon S3 Storage Lens 儀表板組態詳細資訊
](storage_lens_viewing.md)
+ [

# 使用 S3 Storage Lens 管理 AWS 資源標籤
](storage-lens-groups-manage-tags-dashboard.md)
+ [

# 使用 Amazon S3 Storage Lens 的 Helper 檔案
](S3LensHelperFilesCLI.md)

# 建立 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)。

# 更新 Amazon S3 Storage Lens 儀表板
<a name="storage_lens_editing"></a>

 Amazon S3 Storage Lens 預設儀表板為 `default-account-dashboard`。此儀表板是由 Amazon S3 預先設定，可協助您在主控台上以視覺化方式呈現整個帳戶彙總的免費和進階指標的摘要洞見和趨勢。您無法修改預設儀表板的組態範圍，但您可以將指標選項從免費指標升級為付費進階指標和建議、設定選用指標匯出，甚至停用預設儀表板。預設儀表板無法刪除，且只能停用。如需詳細資訊，請參閱[使用 S3 主控台](storage_lens_console_deleting.md)。

## 使用 S3 主控台
<a name="storage_lens_console_editing"></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. 在左導覽窗格中，選擇 **Storage Lens, Dashboards** (Storage Lens、儀表板)。

1. 選擇您要編輯的儀表板。

1. 選擇**檢視儀表板組態**。

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 在儀表板中包含或排除的區域和儲存貯體。
**注意**  
您可以包含或排除區域和儲存貯體。在組織中跨成員帳戶建立組織層級儀表板時，此選項會僅限於「區域」。
您最多可以選擇 50 個要包含或排除的儲存貯體。

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

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

**步驟 3：更新您的 Storage Lens 方案 設定指標選擇**

1. 在 **Storage Lens 層****指標選擇**區段中，更新您要為此儀表板彙總的指標層。
**注意**  
如果您要從**免費方案**更新為**進階方案**，則需要更新您的**指標彙總**設定。若要更新您的**指標彙總設定**，請參閱**步驟 4：更新您的指標彙總**。
如果您要將 Storage Lens 方案從**進階方案**更新為**免費方案**，則不需要更新任何**指標彙總**設定。**指標彙總**功能僅適用於**進階層**指標類別。

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

1. 若要啟用進階指標，請選擇**進階層**。這些選項包括字首彙總、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. 如果您已啟用**字首彙總**，請指定儀表板和**字首深度的最低字首閾值**。 ****然後，選擇**下一步**以儲存並繼續。

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

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

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

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
```

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

**Example – 使用進階指標和建議來更新 Amazon S3 Storage Lens 組態**  
下列範例示範如何在適用於 Java 的 SDK 中使用進階指標和建議來更新預設 S3 Storage Lens 組態：  

```
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.ActivityMetrics;
import com.amazonaws.services.s3control.model.BucketLevel;
import com.amazonaws.services.s3control.model.Format;
import com.amazonaws.services.s3control.model.Include;
import com.amazonaws.services.s3control.model.OutputSchemaVersion;
import com.amazonaws.services.s3control.model.PrefixLevel;
import com.amazonaws.services.s3control.model.PrefixLevelStorageMetrics;
import com.amazonaws.services.s3control.model.PutStorageLensConfigurationRequest;
import com.amazonaws.services.s3control.model.S3BucketDestination;
import com.amazonaws.services.s3control.model.SSES3;
import com.amazonaws.services.s3control.model.SelectionCriteria;
import com.amazonaws.services.s3control.model.StorageLensAwsOrg;
import com.amazonaws.services.s3control.model.StorageLensConfiguration;
import com.amazonaws.services.s3control.model.StorageLensDataExport;
import com.amazonaws.services.s3control.model.StorageLensDataExportEncryption;
import com.amazonaws.services.s3control.model.StorageLensTag;

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

import static com.amazonaws.regions.Regions.US_WEST_2;

public class UpdateDefaultConfigWithPaidFeatures {

    public static void main(String[] args) {
        String configurationId = "default-account-dashboard"; // This configuration ID cannot be modified.
        String sourceAccountId = "111122223333";

        try {
            SelectionCriteria selectionCriteria = new SelectionCriteria()
                    .withDelimiter("/")
                    .withMaxDepth(5)
                    .withMinStorageBytesPercentage(10.0);
            PrefixLevelStorageMetrics prefixStorageMetrics = new PrefixLevelStorageMetrics()
                    .withIsEnabled(true)
                    .withSelectionCriteria(selectionCriteria);
            BucketLevel bucketLevel = new BucketLevel()
                    .withActivityMetrics(new ActivityMetrics().withIsEnabled(true))
                    .withPrefixLevel(new PrefixLevel().withStorageMetrics(prefixStorageMetrics));
            AccountLevel accountLevel = new AccountLevel()
                    .withActivityMetrics(new ActivityMetrics().withIsEnabled(true))
                    .withBucketLevel(bucketLevel);

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

若要存取 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)。

# 停用 Amazon S3 Storage Lens 儀表板
<a name="storage_lens_disabling"></a>

您可以從 Amazon S3 主控台停用 Amazon S3 Storage Lens 儀表板。停用儀表板可防止未來產生指標。已停用的儀表板仍會保留其組態資訊，以便在重新啟用時可以輕鬆恢復。停用的儀表板會保留其歷史資料，直到資料不再可用於查詢。

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

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

**停用 Amazon S3 Storage Lens 儀表板**

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

1. 在左導覽窗格中，選擇 **Storage Lens**、**Dashboards** (儀表板)。

1. 在 **Dashboards** (儀表板) 清單中，選擇您要停用的儀表板，然後選擇清單頂端的 **Disable** (停用)。

1. 在確認頁面上，於文字欄位中輸入儀表板名稱，確認您要停用儀表板，然後選擇**確認**。

# 刪除 Amazon S3 Storage Lens 儀表板
<a name="storage_lens_deleting"></a>

您無法刪除預設儀表板。不過，您可以停用它。在刪除您已建立的儀表板之前，請考慮下列事項：
+ 除了刪除儀表板之外，您還可以*停用*儀表板，以便將來可以重新啟用儀表板。如需詳細資訊，請參閱[使用 S3 主控台](storage_lens_console_disabling.md)。
+ 刪除儀表板會刪除與其相關聯的所有組態設定。
+ 刪除儀表板會使所有歷史指標資料無法使用。這些歷史資料仍會保留 15 個月。如果您想要再次存取此資料，請在與已刪除的主要區域相同的主要區域中建立具有相同名稱的儀表板。

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

您可以從 Amazon S3 主控台刪除 Amazon S3 Storage Lens 儀表板。不過，刪除儀表板可防止未來產生指標。

**正在刪除 Amazon S3 Storage Lens 儀表板**

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

1. 在左導覽窗格中，選擇 **Storage Lens**、**Dashboards** (儀表板)。

1. 在 **Dashboards** (儀表板) 清單中，選擇您要刪除的儀表板，然後選擇清單頂端的 **Delete** (刪除)。

1. 在**刪除儀表板**頁面上，於文字欄位中輸入儀表板名稱，確認您要刪除儀表板。然後選擇 **Confirm** (確認)。

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

**Example**  
 下列範例會刪除 S3 Storage Lens 組態。若要使用這些範例，請以您自己的資訊取代 `user input placeholders`。  

```
aws s3control delete-storage-lens-configuration --account-id=222222222222 --region=us-east-1 --config-id=your-configuration-id
```

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

**Example – 刪除 Amazon S3 Storage Lens 儀表板組態**  
下列範例示範如何使用適用於 Java 的 SDK 刪除 S3 Storage Lens 組態：  

```
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.DeleteStorageLensConfigurationRequest;

import static com.amazonaws.regions.Regions.US_WEST_2;

public class DeleteDashboard {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "111122223333";
        try {
            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            s3ControlClient.deleteStorageLensConfiguration(new DeleteStorageLensConfigurationRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
            );
        } 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();
        }
    }
}
```

# 列出 Amazon S3 Storage Lens 儀表板
<a name="storage_lens_list_dashboard"></a>

 

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

**列出 S3 Storage Lens 儀表板**

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

1. 在左側導覽窗格中，導覽至 **Storage Lens**。

1. 選擇**儀表板**。您現在可以在 中檢視儀表板 AWS 帳戶。

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

**Example**  
下列範例命令會列出 中的 S3 Storage Lens 儀表板 AWS 帳戶。若要使用這些範例，請以您自己的資訊取代 `user input placeholders`。  

```
aws s3control list-storage-lens-configurations --account-id=222222222222 --region=us-east-1 --next-token=abcdefghij1234
```

**Example**  
下列範例會列出不含下一個權杖的 Amazon S3 Storage Lens 組態。若要使用這些範例，請以您自己的資訊取代 `user input placeholders`。  

```
aws s3control list-storage-lens-configurations --account-id=222222222222 --region=us-east-1
```

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

**Example – 列出 S3 Storage Lens 儀表板組態**  
下列範例示範如何在適用於 Java 的 SDK 中列出 S3 Storage Lens 組態。若要使用此範例，請以您自己的資訊取代 `user input placeholders` (針對每個範例描述)。  

```
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.ListStorageLensConfigurationEntry;
import com.amazonaws.services.s3control.model.ListStorageLensConfigurationsRequest;

import java.util.List;

import static com.amazonaws.regions.Regions.US_WEST_2;

public class ListDashboard {

    public static void main(String[] args) {
        String sourceAccountId = "111122223333";
        String nextToken = "nextToken";

        try {
            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            final List<ListStorageLensConfigurationEntry> configurations =
                    s3ControlClient.listStorageLensConfigurations(new ListStorageLensConfigurationsRequest()
                            .withAccountId(sourceAccountId)
                            .withNextToken(nextToken)
                    ).getStorageLensConfigurationList();

            System.out.println(configurations.toString());
        } 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();
        }
    }
}
```

# 檢視 Amazon S3 Storage Lens 儀表板組態詳細資訊
<a name="storage_lens_viewing"></a>

您可以從 Amazon S3 主控台 AWS CLI和適用於 Java 的 SDK 檢視 Amazon S3 Storage Lens 儀表板。

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

**檢視 S3 Storage Lens 儀表板組態詳細資訊**

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

1. 在左側導覽窗格上，導覽至 **Storage Lens**。

1. 選擇**儀表板**。

1. 從**儀表板**清單選擇您要檢視的儀表板。您現在可以檢視 Storage Lens 儀表板的詳細資訊。

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

**Example**  
下列範例會擷取 S3 Storage Lens 組態，以便您檢視組態詳細資訊。若要使用這些範例，請以您自己的資訊取代 `user input placeholders`。  

```
aws s3control get-storage-lens-configuration --account-id=222222222222 --config-id=your-configuration-id --region=us-east-1
```

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

**Example – 擷取和檢視 S3 Storage Lens 組態**  
下列範例示範如何在適用於 Java 的 SDK 中擷取 S3 Storage Lens 組態，以便您檢視組態詳細資訊。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。  

```
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.GetStorageLensConfigurationRequest;
import com.amazonaws.services.s3control.model.GetStorageLensConfigurationResult;
import com.amazonaws.services.s3control.model.StorageLensConfiguration;

import static com.amazonaws.regions.Regions.US_WEST_2;

public class GetDashboard {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "111122223333";

        try {
            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            final StorageLensConfiguration configuration =
                    s3ControlClient.getStorageLensConfiguration(new GetStorageLensConfigurationRequest()
                            .withAccountId(sourceAccountId)
                            .withConfigId(configurationId)
                    ).getStorageLensConfiguration();

            System.out.println(configuration.toString());
        } 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();
        }
    }
}
```

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

每個 Amazon S3 Storage Lens 儀表板都會視為具有自己的 Amazon Resource Name (ARN) AWS 的資源。因此，當您設定 Storage Lens 儀表板時，您可以選擇將 AWS 資源標籤新增至儀表板。每個 Storage Lens 儀表板最多可新增 50 個標籤。若要建立包含標籤的 Storage Lens 儀表板，您必須具有下列 [S3 Storage Lens 許可](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage_lens_iam_permissions.html)：
+ `s3:ListStorageLensConfigurations`
+ `s3:GetStorageLensConfiguration`
+ `s3:GetStorageLensConfigurationTagging`
+ `s3:PutStorageLensConfiguration`
+ ` s3:PutStorageLensConfigurationTagging`

您可以使用 AWS 資源標籤，根據部門、業務單位或專案來分類資源。這在您擁有許多相同類型的資源時很有用。藉由套用標籤，您可以根據先前指派的標籤，快速識別特定的 S3 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-add-tags.md)
+ [

# 擷取 Storage Lens 儀表板 AWS 的資源標籤
](storage-lens-get-tags.md)
+ [

# 更新 Storage Lens 儀表板標籤
](storage-lens-update-tags.md)
+ [

# 從 S3 Storage Lens 儀表板刪除 AWS 資源標籤
](storage-lens-dashboard-delete-tags.md)

# 將 AWS 資源標籤新增至 Storage Lens 儀表板
<a name="storage-lens-add-tags"></a>

下列範例示範如何將 AWS 資源標籤新增至 S3 Storage Lens 儀表板。您可以使用 Amazon S3 主控台、 AWS Command Line Interface (AWS CLI) 和 新增資源標籤 適用於 Java 的 AWS SDK。

## 使用 S3 主控台
<a name="storage-lens-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. 選擇**儀表板**。

1. 選擇您要更新之 Storage Lens 儀表板的選項按鈕。接著選擇 **Edit** (編輯)。

1. 在**一般** 下，選擇**新增標籤**。

1. 在**新增標籤**頁面上，新增金鑰/值對。
**注意**  
新增與現有標籤具有相同索引鍵的標籤，將會覆寫先前的標籤值。

1. (選用) 若要新增多個標籤，請再次選擇**新增標籤**以繼續新增項目。您最多可以將 50 個 AWS 資源標籤新增至 Storage Lens 儀表板。

1. (選用) 如果您要移除新增的項目，請在您想移除的標籤旁選擇**移除**。

1. 選擇**儲存變更**。

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

**Example**  
下列範例命令會將標籤新增至 S3 Storage Lens 儀表板組態。若要使用這些範例，請以您自己的資訊取代 `user input placeholders`。  

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

## 使用適用於 Java 的 AWS 開發套件
<a name="storage-lens-add-tags-sdk-java"></a>

下列範例會在適用於 Java 的 SDK 中將標籤新增至 Amazon S3 Storage Lens 組態。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。

**Example – 將標籤新增至 S3 Storage Lens 組態**  

```
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.PutStorageLensConfigurationTaggingRequest;
import com.amazonaws.services.s3control.model.StorageLensTag;

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

import static com.amazonaws.regions.Regions.US_WEST_2;

public class PutDashboardTagging {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "111122223333";

        try {
            List<StorageLensTag> tags = Arrays.asList(
                    new StorageLensTag().withKey("key-1").withValue("value-1"),
                    new StorageLensTag().withKey("key-2").withValue("value-2")
            );

            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            s3ControlClient.putStorageLensConfigurationTagging(new PutStorageLensConfigurationTaggingRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
                    .withTags(tags)
            );
        } 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-get-tags"></a>

下列範例示範如何擷取 S3 Storage Lens 儀表板 AWS 的資源標籤。您可以使用 Amazon S3 主控台、 AWS Command Line Interface (AWS CLI) 和 取得資源標籤 適用於 Java 的 AWS SDK。

# 使用 S3 主控台
<a name="storage-lens-get-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. 選擇**儀表板**。

1. 選擇您要檢視之 Storage Lens 儀表板組態的選項按鈕。然後，選擇**檢視儀表板組態**。

1. 在**標籤**下，檢閱與儀表板相關聯的標籤。

1. (選用) 如果您想要新增標籤，請選擇**編輯**。然後，選擇**新增標籤**。在**新增標籤**頁面上，新增金鑰/值對。
**注意**  
新增與現有標籤具有相同索引鍵的標籤，將會覆寫先前的標籤值。

1. (選用) 如果您要移除新增的項目，請在您想移除的標籤旁選擇**移除**。

1. 選擇**儲存變更**。

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

**Example**  
下列範例命令會擷取 S3 Storage Lens 儀表板組態的標籤。若要使用這些範例，請以您自己的資訊取代 `user input placeholders`。  

```
aws s3control get-storage-lens-configuration-tagging --account-id=222222222222 --region=us-east-1 --config-id=your-configuration-id --tags=file://./tags.json
```

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

**Example – 取得 S3 Storage Lens 儀表板組態的標籤**  
下列範例示範如何在適用於 Java 的 SDK 中擷取 S3 Storage Lens 儀表板組態的標籤。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。  

```
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.DeleteStorageLensConfigurationRequest;
import com.amazonaws.services.s3control.model.GetStorageLensConfigurationTaggingRequest;
import com.amazonaws.services.s3control.model.StorageLensTag;

import java.util.List;

import static com.amazonaws.regions.Regions.US_WEST_2;

public class GetDashboardTagging {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "111122223333";
        try {
            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            final List<StorageLensTag> s3Tags = s3ControlClient
                    .getStorageLensConfigurationTagging(new GetStorageLensConfigurationTaggingRequest()
                            .withAccountId(sourceAccountId)
                            .withConfigId(configurationId)
                    ).getTags();

            System.out.println(s3Tags.toString());
        } 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-update-tags"></a>

下列範例示範如何使用 Amazon S3 主控台 AWS Command Line Interface (AWS CLI) 和 更新 Storage Lens 儀表板標籤 適用於 Java 的 AWS SDK。

## 使用 S3 主控台
<a name="storage-lens-dashboard-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. 選擇**儀表板**。

1. 選擇您要檢視之 Storage Lens 儀表板組態的選項按鈕。然後，選擇**檢視儀表板組態**。

1. 在**標籤**下，檢閱與儀表板相關聯的標籤。

1. (選用) 如果您想要新增標籤，請選擇**編輯**。然後，選擇**新增標籤**。在**新增標籤**頁面上，新增金鑰/值對。
**注意**  
新增與現有標籤具有相同索引鍵的標籤，將會覆寫先前的標籤值。

1. (選用) 如果您要移除新增的項目，請在您想移除的標籤旁選擇**移除**。

1. 選擇**儲存變更**。

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

**Example**  
下列範例命令會新增或取代現有 Amazon S3 Storage Lens 儀表板組態上的標籤。若要使用這些範例，請以您自己的資訊取代 `user input placeholders`。  

```
aws s3control put-storage-lens-configuration-tagging --account-id=111122223333 --config-id=example-dashboard-configuration-id --region=us-east-1 --config-id=your-configuration-id
```

## 使用適用於 Java 的 AWS 開發套件
<a name="storage-lens-dashboard-update-tags-sdk-java"></a>

下列 適用於 Java 的 AWS SDK 範例會更新現有 Storage Lens 儀表板上的 AWS 資源標籤。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。

**Example – 更新現有 Storage Lens 儀表板組態上的標籤**  

```
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.PutStorageLensConfigurationTaggingRequest;
import com.amazonaws.services.s3control.model.StorageLensTag;

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

import static com.amazonaws.regions.Regions.US_WEST_2;

public class PutDashboardTagging {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "111122223333";

        try {
            List<StorageLensTag> tags = Arrays.asList(
                    new StorageLensTag().withKey("key-1").withValue("value-1"),
                    new StorageLensTag().withKey("key-2").withValue("value-2")
            );

            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            s3ControlClient.putStorageLensConfigurationTagging(new PutStorageLensConfigurationTaggingRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
                    .withTags(tags)
            );
        } 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();
        }
    }
}
```

# 從 S3 Storage Lens 儀表板刪除 AWS 資源標籤
<a name="storage-lens-dashboard-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://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)：// 開啟 Amazon S3 主控台。

1. 在左側導覽窗格中，導覽至 **Storage Lens**。

1. 選擇**儀表板**。

1. 選擇您要檢視之 Storage Lens 儀表板組態的選項按鈕。然後，選擇**檢視儀表板組態**。

1. 在**標籤**下，檢閱與儀表板相關聯的標籤。

1. 選擇您要移除之標籤旁的**移除**。

1. 選擇**儲存變更**。

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

下列 AWS CLI 命令會從現有的 Storage Lens 儀表板刪除 AWS 資源標籤。若要使用此範例命令，請以您自己的資訊取代 `user input placeholders`。

**Example**  

```
aws s3control delete-storage-lens-configuration-tagging --account-id=222222222222 --config-id=your-configuration-id --region=us-east-1
```

## 使用適用於 Java 的 AWS 開發套件
<a name="storage-lens-dashboard-delete-tags-sdk-java"></a>

下列 適用於 Java 的 AWS SDK 範例會使用您在帳戶 中指定的 Amazon Resource Name (ARN)，從 Storage Lens 儀表板刪除 AWS 資源標籤`111122223333`。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。

**Example – 刪除 S3 Storage Lens 儀表板組態的標籤**  

```
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.DeleteStorageLensConfigurationTaggingRequest;

import static com.amazonaws.regions.Regions.US_WEST_2;

public class DeleteDashboardTagging {

    public static void main(String[] args) {
        String configurationId = "ConfigurationId";
        String sourceAccountId = "111122223333";
        try {
            AWSS3Control s3ControlClient = AWSS3ControlClient.builder()
                    .withCredentials(new ProfileCredentialsProvider())
                    .withRegion(US_WEST_2)
                    .build();

            s3ControlClient.deleteStorageLensConfigurationTagging(new DeleteStorageLensConfigurationTaggingRequest()
                    .withAccountId(sourceAccountId)
                    .withConfigId(configurationId)
            );
        } 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();
        }
    }
}
```

# 使用 Amazon S3 Storage Lens 的 Helper 檔案
<a name="S3LensHelperFilesCLI"></a>

為您的範例使用下列 JSON 檔案及其金鑰輸入。

## 使用 JSON 的 S3 Storage Lens 範例組態
<a name="S3LensHelperFilesSampleConfigurationCLI"></a>

**Example `config.json`**  
`config.json` 檔案包含 S3 Storage Lens 組織層級*進階指標和建議*組態的詳細資訊。若要使用下列範例，請以您自己的資訊取代 `user input placeholders`。  
進階指標和建議需支付額外費用。如需詳細資訊，請參閱[進階指標和建議](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage_lens_basics_metrics_recommendations.html#storage_lens_basics_metrics_selection)。

```
{
  "Id": "SampleS3StorageLensConfiguration", //Use this property to identify your S3 Storage Lens configuration.
  "AwsOrg": { //Use this property when enabling S3 Storage Lens for AWS Organizations.
    "Arn": "arn:aws:organizations::123456789012:organization/o-abcdefgh"
  },
  "AccountLevel": {
    "ActivityMetrics": {
      "IsEnabled":true
    },
    "AdvancedCostOptimizationMetrics": {
      "IsEnabled":true
    },
    "AdvancedDataProtectionMetrics": {
      "IsEnabled":true
    },
    "DetailedStatusCodesMetrics": {
      "IsEnabled":true
    },
    "BucketLevel": {
      "ActivityMetrics": {
        "IsEnabled":true
      },
      "AdvancedDataProtectionMetrics": {
      "IsEnabled":true
      },
      "AdvancedCostOptimizationMetrics": {
        "IsEnabled":true
      },
      "DetailedStatusCodesMetrics": {
        "IsEnabled":true
      },
      "PrefixLevel":{
        "StorageMetrics":{
          "IsEnabled":true,
          "SelectionCriteria":{
            "MaxDepth":5,
            "MinStorageBytesPercentage":1.25,
            "Delimiter":"/"
          }
        }
      }
    }
  },
  "Exclude": { //Replace with "Include" if you prefer to include Regions.
    "Regions": [
      "eu-west-1"
    ],
    "Buckets": [ //This attribute is not supported for AWS Organizations-level configurations.
      "arn:aws:s3:::amzn-s3-demo-source-bucket"
    ]
  },
  "IsEnabled": true, //Whether the configuration is enabled
  "DataExport": { //Details about the metrics export
    "S3BucketDestination": {
      "OutputSchemaVersion": "V_1",
      "Format": "CSV", //You can add "Parquet" if you prefer.
      "AccountId": "111122223333",
      "Arn": "arn:aws:s3:::
amzn-s3-demo-destination-bucket", // The destination bucket for your metrics export must be in the same Region as your S3 Storage Lens configuration. 
      "Prefix": "prefix-for-your-export-destination",
      "Encryption": {
        "SSES3": {}
      }
    },
    "CloudWatchMetrics": {
      "IsEnabled": true
    }
  }
}
```

## 使用 JSON Storage Lens 群組的 S3 Storage Lens 範例組態
<a name="StorageLensGroupsHelperFilesCLI"></a>

**Example `config.json`**  

`config.json` 檔案包含您在使用 Storage Lens 群組時要套用至 Storage Lens 組態的詳細資訊。若要使用該範例，請將 `user input placeholders` 取代為您自己的資訊。

若要將所有 Storage Lens 群組連接至儀表板，請使用下列語法更新您的 Storage Lens 組態：

```
{
  "Id": "ExampleS3StorageLensConfiguration",
  "AccountLevel": {
    "ActivityMetrics": {
      "IsEnabled":true
    },
    "AdvancedCostOptimizationMetrics": {
      "IsEnabled":true
    },
    "AdvancedDataProtectionMetrics": {
      "IsEnabled":true
    },
    "BucketLevel": {
      "ActivityMetrics": {
      "IsEnabled":true
      },
    "StorageLensGroupLevel": {},
  "IsEnabled": true
}
```

若您的 Storage Lens 儀表板組態中只要包含兩個 Storage Lens 群組 (*slg-1* 和 *slg-2*)，請使用下列語法：

```
{
  "Id": "ExampleS3StorageLensConfiguration",
  "AccountLevel": {
    "ActivityMetrics": {
      "IsEnabled":true
    },
    "AdvancedCostOptimizationMetrics": {
      "IsEnabled":true
    },
    "AdvancedDataProtectionMetrics": {
      "IsEnabled":true
    },
    "BucketLevel": {
      "ActivityMetrics": {
      "IsEnabled":true
      },
   "StorageLensGroupLevel": {
        "SelectionCriteria": {
            "Include": [
                "arn:aws:s3:us-east-1:111122223333:storage-lens-group/slg-1",
                "arn:aws:s3:us-east-1:444455556666:storage-lens-group/slg-2"
            ]
    },
  "IsEnabled": true
}
```

若只有特定 Storage Lens 群組不要連接至儀表板組態，請使用下列語法：

```
{
  "Id": "ExampleS3StorageLensConfiguration",
  "AccountLevel": {
    "ActivityMetrics": {
      "IsEnabled":true
    },
    "AdvancedCostOptimizationMetrics": {
      "IsEnabled":true
    },
    "AdvancedDataProtectionMetrics": {
      "IsEnabled":true
    },
    "BucketLevel": {
      "ActivityMetrics": {
      "IsEnabled":true
      },
   "StorageLensGroupLevel": {
        "SelectionCriteria": {
            "Exclude": [
                "arn:aws:s3:us-east-1:111122223333:storage-lens-group/slg-1",
                "arn:aws:s3:us-east-1:444455556666:storage-lens-group/slg-2"
            ]
    },
  "IsEnabled": true
}
```

## 使用 JSON 的 S3 Storage Lens 範例標籤組態
<a name="S3LensHelperFilesSampleConfigurationTagsCLI"></a>

**Example `tags.json`**  
`tags.json` 檔案包含您想要套用至 S3 Storage Lens 組態的標籤。若要使用此範例，請以您自己的資訊取代 `user input placeholders`。  

```
[
    {
        "Key": "key1",
        "Value": "value1"
    },
    {
        "Key": "key2",
        "Value": "value2"
    }
]
```

## S3 Storage Lens 範例組態 IAM 許可
<a name="S3LensHelperFilesSampleConfigurationIAMPermissionsCLI"></a>

**Example `permissions.json` - 特定儀表板名稱**  
此範例政策顯示已指定特定儀表板名稱的 S3 Storage Lens IAM `permissions.json` 檔案。將 *`value1`*、`us-east-1`、`your-dashboard-name` 和 `example-account-id` 取代為您自己的值。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetStorageLensConfiguration",
                "s3:DeleteStorageLensConfiguration",
                "s3:PutStorageLensConfiguration"
            ],
            "Condition": {
                "StringEquals": {
                    "aws:ResourceTag/key1": "value1"
                }
            },
            "Resource": "arn:aws:s3:us-east-1:111122223333:storage-lens/your-dashboard-name"
        }
    ]
}
```

**Example `permissions.json` - 沒有特定的儀表板名稱**  
此範例政策顯示未指定特定儀表板名稱的 S3 Storage Lens IAM `permissions.json` 檔案。用您自己的值取代 *`value1`*、`us-east-1` 和 `example-account-id`。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetStorageLensConfiguration",
                "s3:DeleteStorageLensConfiguration",
                "s3:PutStorageLensConfiguration"
            ],
            "Condition": {
                "StringEquals": {
                    "aws:ResourceTag/key1": "value1"
                }
            },
            "Resource": "arn:aws:s3:us-east-1:111122223333:storage-lens/*"
        }
    ]
}
```