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

删除 Amazon S3 on Outposts 存储桶中的对象

对象是 Amazon S3 on Outposts 中存储的基础实体。每个对象都储存在一个存储桶中。您必须使用访问点才能访问 Outpost 存储桶中的任何对象。当您指定存储桶以执行对象操作时,请使用访问点 Amazon Resource Name (ARN),其中包括 Outpost 所属区域的 Amazon Web Services 区域代码、Amazon Web Services 账户 ID、Outpost ID 和访问点名称。以下示例显示对象操作中用于 S3 on Outposts 访问点的 ARN 格式:

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 Command Line Interface (Amazon CLI) 和Amazon SDK for Java 从 S3 on Outposts 存储桶删除单个或多个对象。

以下示例显示如何从 S3 on Outposts 存储桶删除单个或多个对象。

delete-object

以下示例使用 Amazon CLI 从 S3 on Outposts 存储桶 (s3-outposts:DeleteObject) 删除一个名为 sample-object.xml 的对象。要使用此命令,请将每个 user input placeholder 替换为您自己的信息。有关此命令的更多信息,请参阅《Amazon CLI 参考》中的 delete-object

aws s3api delete-object --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/accesspoint/example-outposts-access-point --key sample-object.xml
delete-objects

以下示例使用 Amazon CLI 从 S3 on Outposts 存储桶 (s3-outposts:DeleteObject) 删除名为 sample-object.xmltest1.text 的两个对象。要使用此命令,请将每个 user input placeholder 替换为您自己的信息。有关此命令的更多信息,请参阅《Amazon CLI 参考》https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/delete-objects.html中的 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 }

以下示例显示如何从 S3 on Outposts 存储桶删除单个或多个对象。

DeleteObject

以下 S3 on Outposts 示例使用适用于 Java 的 SDK 删除存储桶中的对象。要使用此示例,请指定 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 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(); 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 示例使用适用于 Java 的 SDK 向存储桶上传对象,然后删除对象。要使用此示例,请指定 Outpost 的访问点 ARN。有关更多信息,请参阅《Amazon Simple Storage Service API 参考》中的 DeleteObjects

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 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(); // 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(); } } }