刪除 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、Outpost ID 和存取點名稱:

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

如需 S3 on Outposts 的詳細資訊ARNs,請參閱 S3 on Outposts ARNs的資源

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

下列範例示範如何使用 AWS Command Line Interface (AWS CLI) 和 刪除 S3 on Outposts 儲存貯體中的單一物件或多個物件 AWS SDK for Java。

下列範例示範如何從 S3 on Outposts 儲存貯體中刪除單個物件或多個物件。

delete-object

下列範例使用 AWS CLI從 S3 on Outposts 儲存貯體 (s3-outposts:DeleteObject) 刪除名稱為 sample-object.xml 的物件。若要執行此命令,請以您自己的資訊取代每個 user input placeholder。如需此命令的詳細資訊,請參閱 AWS 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

下列範例使用 AWS CLI從 S3 on Outposts 儲存貯體 (s3-outposts:DeleteObject) 刪除名稱為 sample-object.xmltest1.text 的兩個物件。若要執行此命令,請以您自己的資訊取代每個 user input placeholder。如需此命令的詳細資訊,請參閱 AWS CLI 參考中的 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 範例會使用 SDK for Java 刪除儲存貯體中的物件。若要使用此範例,請指定 Outpost ARN的存取點,以及要刪除之物件的金鑰名稱。如需詳細資訊,請參閱 Amazon Simple Storage Service 參考 DeleteObject 中的 。 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.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適用於 Java 的 上傳,然後刪除儲存貯體中的物件。若要使用此範例,請指定 Outpost ARN 的存取點。如需詳細資訊,請參閱 Amazon Simple Storage Service 參考 DeleteObjects 中的 。 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.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(); } } }