建立 Storage Lens 群組 - Amazon Simple Storage Service

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

建立 Storage Lens 群組

下列範例示範如何使用 Amazon S3 主控台 AWS Command Line Interface (AWS CLI) 和建立 Amazon S3 儲存鏡頭群組 AWS SDK for Java。

建立 Storage Lens 群組
  1. 登入 AWS Management Console 並開啟 Amazon S3 主控台,網址為 https://console.aws.amazon.com/s3/

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

  3. 在左側導覽窗格中,選擇 Storage Lens 群組

  4. 選擇建立 Storage Lens 群組

  5. 在「一般」下方,檢視您的「居住地區」並輸入儲存鏡頭群組名稱

  6. 範圍底下,選擇要套用至 Storage Lens 群組的篩選條件。若要套用多個篩選條件,請選擇篩選條件,然後選擇 ANDOR 邏輯運算子。

    • 針對字首篩選條件,選擇字首,然後輸入字首字串。若要新增多個字首,請選擇新增字首。若要移除字首,請選擇要移除的字首旁的移除

    • 物件標籤篩選條件中,選擇物件標籤,然後輸入物件的鍵/值對。然後,選擇新增標籤。若要移除標籤,請選擇要移除的標籤旁的移除

    • 針對尾碼篩選條件,選擇尾碼,然後輸入尾碼字串。若要新增多個尾碼,請選擇新增尾碼。若要移除尾碼,請選擇要移除的尾碼旁的移除

    • 針對存留期篩選條件,指定物件存留期範圍 (天數)。選擇指定最短物件存留期,然後輸入最短的物件存留期。然後,選擇指定最長物件存留期,並輸入最長的物件存留期。

    • 針對大小篩選條件,指定物件大小範圍和測量單位。選擇指定最小物件大小,然後輸入最小的物件大小。選擇指定最大物件大小,並輸入最大的物件大小。

  7. (選擇性) 對於 AWS 資源標籤,請新增鍵值配對,然後選擇 [新增標籤]。

  8. 選擇建立 Storage Lens 群組

下列範例 AWS CLI 指令會建立儲存鏡頭群組。若要使用此範例命令,請以您自己的資訊取代 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 資源標籤的儲存鏡頭群組。若要使用此範例命令,請以您自己的資訊取代 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 群組組態

下列 AWS SDK for Java 範例會建立儲存鏡頭群組。若要使用此範例,請以您自己的資訊取代 user input placeholders

範例 – 使用單一篩選條件建立 Storage Lens 群組

下列範例會建立名為 Marketing-Department 的 Storage Lens 群組。此群組具有會將存留期範圍指定為 3090 天的物件存留期篩選條件。若要使用此範例,請以您自己的資訊取代 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(); } } }
範例 – 使用包含多個篩選條件的 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(); } } }
範例 – 使用包含多個篩選條件的 OR 運算子建立 Storage Lens 群組

下列範例會建立名為 Marketing-Department 的 Storage Lens 群組。此群組會使用 OR 運算子來套用字首篩選條件 (prefix-1prefix-2prefix3/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(); } } }
範例 — 使用單個濾鏡和兩個 AWS 資源標籤創建存儲鏡頭組

下列範例會建立名為 Marketing-Department、具有尾碼篩選條件的 Storage Lens 群組。此範例也會將兩個 AWS 資源標籤新增至儲存鏡頭群組。若要使用此範例,請以您自己的資訊取代 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 群組組態