列出 Amazon S3 on Outposts 存储桶中的对象 - Amazon Simple Storage Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

列出 Amazon S3 on Outposts 存储桶中的对象

对象是 Amazon S3 on Outposts 中存储的基础实体。每个对象都储存在一个存储桶中。您必须使用访问点才能访问 Outpost 存储桶中的任何对象。当您为对象操作指定桶时,可以使用访问点 Amazon 资源名称(ARN)或访问点别名。有关访问点别名的更多信息,请参阅为您的 S3 on Outposts 桶访问点使用桶式别名

以下示例显示了 S3 on Outposts 访问点的 ARN 格式,其中包括 Outpost 所属区域的 Amazon Web Services 区域 代码、Amazon Web Services 账户 ID、Outpost 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 上。当 Amazon 安装 Outpost 机架时,您的数据将保留在 Outpost 的本地,以满足数据驻留要求。您的对象永远不会离开您的 Outpost,也不在 Amazon Web Services 区域 中。由于 Amazon Web Services Management Console 托管在区域内,您无法使用控制台上传或管理 Outpost 中的对象。但是,您可以使用 REST API、Amazon Command Line Interface (Amazon CLI) 和 Amazon SDK 通过访问点上传和管理对象。

以下示例显示如何使用 Amazon CLI 和Amazon SDK for Java 列出 S3 on Outposts 存储桶中的对象。

以下示例使用 Amazon CLI 列出 S3 on Outposts 存储桶 (s3-outposts:ListObjectsV2) 中的对象。要使用此命令,请将每个 user input placeholder 替换为您自己的信息。有关此命令的更多信息,请参阅《Amazon CLI 参考》中的 list-objects-v2

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

通过 Amazon 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 的 SDK 列出桶中的对象。要使用此示例,请将每个 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 Amazon 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(); } } }