刪除 Amazon S3 on Outposts 儲存貯體中的物件
物件是存放在 Amazon S3 on Outposts 中的基本實體。每個物件都包含在儲存貯體中。您必須使用存取點來存取 Outpost 儲存貯體中的任何物件。針對物件操作指定儲存貯體時,您可以使用存取點 Amazon Resource Name (ARN) 或存取點別名。如需存取點別名的詳細資訊,請參閱 針對您的 S3 on Outposts 儲存貯體存取點使用儲存貯體樣式別名。
以下範例顯示了 S3 on Outposts 存取點的 ARN 格式,其中包括 Outpost 所在區域的 AWS 區域代碼、AWS 帳戶 ID、Outposts 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 管理主控台 託管在區域內,您無法使用主控台上傳或管理 Outpost 中的物件。然而,您可以使用 REST API、AWS Command Line Interface (AWS CLI) 以及 AWS SDK 透過存取點上傳和管理您的物件。
下列範例示範如何透過使用 AWS Command Line Interface (AWS CLI) 和 適用於 Java 的 AWS SDK 來刪除 S3 on Outposts 儲存貯體中的單個物件或多個物件。
下列範例示範如何從 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.xml 和 test1.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 範例使用適用於 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 範例使用適用於 Java 的開發套件,在儲存貯體中上傳,然後刪除物件。若要使用此範例,請為 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 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();
}
}
}