Amazon S3 on Outposts バケット内のオブジェクトを一覧表示する - Amazon Simple Storage Service

Amazon S3 on Outposts バケット内のオブジェクトを一覧表示する

オブジェクトは、Amazon S3 on Outposts に保存される基本エンティティです。すべてのオブジェクトはバケット内に保存されます。Outpost バケット内の任意のオブジェクトにアクセスするには、アクセスポイントを使用する必要があります。オブジェクト操作のためにバケットを指定するときには、アクセスポイントの Amazon リソースネーム (ARN) またはアクセスポイントエイリアスを使用します。アクセスポイントエイリアスの詳細については、「S3 on Outposts アクセスポイントでのバケット形式のエイリアスの使用」を参照してください。

次の例は、S3 on Outposts アクセスポイントの ARN 形式を示し、これは、Outpost が属するリージョンの AWS リージョン コード、AWS アカウント 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 に保存されます。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 バケット内のオブジェクトを一覧表示する方法を示しています。

次の例では、S3 on Outposts バケット (s3-outposts:ListObjectsV2) 内のオブジェクトを、AWS CLI を使用して一覧表示します。このコマンドを使用するには、それぞれの 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 の例では、SDK for Java を使用してバケット内のオブジェクトを一覧表示します。この例を実行するには、それぞれの user input placeholder をユーザー自身の情報に置き換えます。

重要

この例では、ListObjectsAPI オペレーションの最新リビジョンである ListObjectsV2 を使用します。この改訂版の 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(); } } }