列出 Amazon S3 on Outposts 儲存貯體中的物件 - Amazon S3 on Outposts

列出 Amazon S3 on Outposts 儲存貯體中的物件

物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時,您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊,請參閱 針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名

以下範例顯示了 S3 on Outposts 存取點的 ARN 格式,其中包括 Outpost 所在區域的 AWS 區域代碼、AWS 帳戶 ID、Outposts ID,以及存取點名稱:

arn:aws:s3-outposts:region:account-id:outpost/outpost-id/accesspoint/accesspoint-name

如需 S3 on Outposts ARN 的詳細資訊,請參閱 適用於 S3 on Outposts 的資源 ARN

注意

對於 Amazon S3 on Outposts,物件資料始終存放在 Outpost 上。當 AWS 安裝 Outpost 機架時,您的資料將保留在本機 Outpost 上,以滿足資料駐留的要求。您的物件永遠不會離開您的 Outpost,也不會在 AWS 區域 中。由於 AWS Management Console 託管在區域內,您無法使用主控台上傳或管理 Outpost 中的物件。然而,您可以使用 REST API、AWS Command Line Interface (AWS CLI) 以及 AWS SDK 透過存取點上傳和管理您的物件。

下列範例示範如何使用 AWS CLI 和 AWS SDK for Java 列出 S3 on Outposts 儲存貯體中的物件。

下列範例使用 AWS CLI 列出 S3 on Outposts 儲存貯體 (s3-outposts:ListObjectsV2) 中的物件。若要執行此命令,請以您自己的資訊取代每個 user input placeholder。如需此命令的詳細資訊,請參閱 AWS CLI 參考中的 list-objects-v2

aws s3api list-objects-v2 --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point
注意

透過 AWS SDK 將此動作與 Amazon S3 on Outposts 搭配使用時,您可以提供 Outposts 存取點 ARN 取代儲存貯體名稱,格式如下:arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-Outposts-Access-Point。如需 S3 on Outposts ARN 的詳細資訊,請參閱 適用於 S3 on Outposts 的資源 ARN

下列 S3 on Outposts 範例使用適用於 Java 的開發套件,在儲存貯體中列出物件。若要使用此範例,請以您自己的資訊取代每個 user input placeholder

重要

此範例使用 ListObjectsV2,這是 ListObjects API 操作的最新修訂版。建議您使用此修訂版本後的 API 操作進行應用程式進行開發。為了回溯相容性,Amazon S3 會繼續支援此 API 操作的舊版本。

import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.model.ListObjectsV2Request; import com.amazonaws.services.s3.model.ListObjectsV2Result; import com.amazonaws.services.s3.model.S3ObjectSummary; public class ListObjectsV2 { public static void main(String[] args) { String accessPointArn = "*** access point ARN ***"; try { // This code expects that you have AWS credentials set up per: // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .enableUseArnRegion() .build(); System.out.println("Listing objects"); // maxKeys is set to 2 to demonstrate the use of // ListObjectsV2Result.getNextContinuationToken() ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(accessPointArn).withMaxKeys(2); ListObjectsV2Result result; do { result = s3Client.listObjectsV2(req); for (S3ObjectSummary objectSummary : result.getObjectSummaries()) { System.out.printf(" - %s (size: %d)\n", objectSummary.getKey(), objectSummary.getSize()); } // If there are more than maxKeys keys in the bucket, get a continuation token // and list the next objects. String token = result.getNextContinuationToken(); System.out.println("Next Continuation Token: " + token); req.setContinuationToken(token); } while (result.isTruncated()); } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it 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(); } } }