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 Command Line Interface (AWS CLI) と AWS SDK for Java を使用して、S3 on Outposts バケット内の単一のオブジェクトまたは複数のオブジェクトを削除する方法を示しています。
以下の例は、S3 on Outposts バケットから単一のオブジェクトまたは複数のオブジェクトを削除する方法を示しています。
- delete-object
-
次の例では、
sample-object.xml
を使用して、S3 on Outposts バケット (s3-outposts:DeleteObject
) から AWS CLI という名前のオブジェクトを削除します。このコマンドを使用するには、それぞれの
をユーザー自身の情報に置き換えます。このコマンドの詳細については、「AWS CLI リファレンスuser input placeholder
」の「delete-object」を参照してください。 aws s3api delete-object --bucket arn:aws:s3-outposts:
region
:123456789012
:outpost/op-01ac5d28a6a232904
/accesspoint/example-outposts-access-point
--keysample-object.xml
- delete-objects
-
以下の例では、AWS CLI を使用して、S3 on Outposts バケット (
s3-outposts:DeleteObject
) からsample-object.xml
とtest1.text
という名前の 2 つのオブジェクトを削除します。このコマンドを使用するには、それぞれの
をユーザー自身の情報に置き換えます。このコマンドの詳細については、「AWS CLI リファレンスuser input placeholder
」の「delete-objects」を参照してください。 aws s3api delete-objects --bucket arn:aws:s3-outposts:
region
:123456789012
:outpost/op-01ac5d28a6a232904
/accesspoint/example-outposts-access-point
--delete file://delete.json delete.json { "Objects": [ { "Key": "test1.txt" }, { "Key": "sample-object.xml" } ], "Quiet": false }
AWS CLI の使用
以下の例は、S3 on Outposts バケットから単一のオブジェクトまたは複数のオブジェクトを削除する方法を示しています。
- delete-object
-
次の例では、
sample-object.xml
を使用して、S3 on Outposts バケット (s3-outposts:DeleteObject
) から AWS CLI という名前のオブジェクトを削除します。このコマンドを使用するには、それぞれの
をユーザー自身の情報に置き換えます。このコマンドの詳細については、「AWS CLI リファレンスuser input placeholder
」の「delete-object」を参照してください。 aws s3api delete-object --bucket arn:aws:s3-outposts:
region
:123456789012
:outpost/op-01ac5d28a6a232904
/accesspoint/example-outposts-access-point
--keysample-object.xml
- delete-objects
-
以下の例では、AWS CLI を使用して、S3 on Outposts バケット (
s3-outposts:DeleteObject
) からsample-object.xml
とtest1.text
という名前の 2 つのオブジェクトを削除します。このコマンドを使用するには、それぞれの
をユーザー自身の情報に置き換えます。このコマンドの詳細については、「AWS CLI リファレンスuser input placeholder
」の「delete-objects」を参照してください。 aws s3api delete-objects --bucket arn:aws:s3-outposts:
region
:123456789012
:outpost/op-01ac5d28a6a232904
/accesspoint/example-outposts-access-point
--delete file://delete.json delete.json { "Objects": [ { "Key": "test1.txt" }, { "Key": "sample-object.xml" } ], "Quiet": false }
次の例では、sample-object.xml
を使用して、S3 on Outposts バケット (s3-outposts:DeleteObject
) から AWS CLI という名前のオブジェクトを削除します。このコマンドを使用するには、それぞれの
をユーザー自身の情報に置き換えます。このコマンドの詳細については、「AWS CLI リファレンスuser input
placeholder
aws s3api delete-object --bucket arn:aws:s3-outposts:
region
:123456789012
:outpost/op-01ac5d28a6a232904
/accesspoint/example-outposts-access-point
--keysample-object.xml
以下の例は、S3 on Outposts バケットから単一のオブジェクトまたは複数のオブジェクトを削除する方法を示しています。
- DeleteObject
-
次の S3 on Outposts の例では、SDK for Java を使用してバケット内のオブジェクトを削除します。この例を使用するには、Outpost のアクセスポイント ARN と、削除するオブジェクトのキー名を指定します。詳細については、Amazon Simple Storage Service API リファレンスの「DeleteObject」を参照してください。
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.DeleteObjectRequest; public class DeleteObject { public static void main(String[] args) { String accessPointArn = "
*** access point ARN ***
"; String keyName = "*** key name ****
"; 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(); s3Client.deleteObject(new DeleteObjectRequest(accessPointArn, keyName)); } 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(); } } } - DeleteObjects
-
次の S3 on Outposts の例では、SDK for Java を使用してバケット内のオブジェクトをアップロードして、削除します。この例を使用するには、Outpost のアクセスポイント ARN を指定します。詳細については、「Amazon Simple Storage Service API リファレンス」の「DeleteObject」を参照してください。
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.DeleteObjectsRequest; import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion; import com.amazonaws.services.s3.model.DeleteObjectsResult; import java.util.ArrayList; public class DeleteObjects { public static void main(String[] args) { String accessPointArn = "arn:aws:s3-outposts:
region
:123456789012
:outpost/op-01ac5d28a6a232904
/accesspoint/example-outposts-access-point
"; 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(); // Upload three sample objects. ArrayList<KeyVersion> keys = new ArrayList<KeyVersion>(); for (int i = 0; i < 3; i++) { String keyName = "delete object example " + i; s3Client.putObject(accessPointArn, keyName, "Object number " + i + " to be deleted."); keys.add(new KeyVersion(keyName)); } System.out.println(keys.size() + " objects successfully created."); // Delete the sample objects. DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(accessPointArn) .withKeys(keys) .withQuiet(false); // Verify that the objects were deleted successfully. DeleteObjectsResult delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest); int successfulDeletes = delObjRes.getDeletedObjects().size(); System.out.println(successfulDeletes + " objects successfully deleted."); } 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(); } } }
AWS SDK for Java の使用
以下の例は、S3 on Outposts バケットから単一のオブジェクトまたは複数のオブジェクトを削除する方法を示しています。
- DeleteObject
-
次の S3 on Outposts の例では、SDK for Java を使用してバケット内のオブジェクトを削除します。この例を使用するには、Outpost のアクセスポイント ARN と、削除するオブジェクトのキー名を指定します。詳細については、Amazon Simple Storage Service API リファレンスの「DeleteObject」を参照してください。
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.DeleteObjectRequest; public class DeleteObject { public static void main(String[] args) { String accessPointArn = "
*** access point ARN ***
"; String keyName = "*** key name ****
"; 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(); s3Client.deleteObject(new DeleteObjectRequest(accessPointArn, keyName)); } 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(); } } } - DeleteObjects
-
次の S3 on Outposts の例では、SDK for Java を使用してバケット内のオブジェクトをアップロードして、削除します。この例を使用するには、Outpost のアクセスポイント ARN を指定します。詳細については、「Amazon Simple Storage Service API リファレンス」の「DeleteObject」を参照してください。
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.DeleteObjectsRequest; import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion; import com.amazonaws.services.s3.model.DeleteObjectsResult; import java.util.ArrayList; public class DeleteObjects { public static void main(String[] args) { String accessPointArn = "arn:aws:s3-outposts:
region
:123456789012
:outpost/op-01ac5d28a6a232904
/accesspoint/example-outposts-access-point
"; 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(); // Upload three sample objects. ArrayList<KeyVersion> keys = new ArrayList<KeyVersion>(); for (int i = 0; i < 3; i++) { String keyName = "delete object example " + i; s3Client.putObject(accessPointArn, keyName, "Object number " + i + " to be deleted."); keys.add(new KeyVersion(keyName)); } System.out.println(keys.size() + " objects successfully created."); // Delete the sample objects. DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(accessPointArn) .withKeys(keys) .withQuiet(false); // Verify that the objects were deleted successfully. DeleteObjectsResult delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest); int successfulDeletes = delObjRes.getDeletedObjects().size(); System.out.println(successfulDeletes + " objects successfully deleted."); } 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(); } } }
次の S3 on Outposts の例では、SDK for Java を使用してバケット内のオブジェクトを削除します。この例を使用するには、Outpost のアクセスポイント ARN と、削除するオブジェクトのキー名を指定します。詳細については、Amazon Simple Storage Service API リファレンスの「DeleteObject」を参照してください。
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.DeleteObjectRequest;
public class DeleteObject {
public static void main(String[] args) {
String accessPointArn = "*** access point ARN ***
";
String keyName = "*** key name ****
";
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();
s3Client.deleteObject(new DeleteObjectRequest(accessPointArn, keyName));
} 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();
}
}
}