使用 AWS SDK for Java 在 Amazon S3 on Outposts 儲存貯體中複製物件 - Amazon S3 on Outposts

使用 AWS SDK for Java 在 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 Management Console 託管在區域內,您無法使用主控台上傳或管理 Outpost 中的物件。然而,您可以使用 REST API、AWS Command Line Interface (AWS CLI) 以及 AWS SDK 透過存取點上傳和管理您的物件。

下列範例示範如何使用 AWS SDK for Java 複製 S3 on Outposts 儲存貯體中的物件。

使用適用於 Java 的 AWS 軟體開發套件

下列 S3 on Outposts 範例使用適用於 Java 的開發套件,將物件複製到同一儲存貯體中的新物件。若要使用此範例,請以您自己的資訊取代 user input placeholders

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.CopyObjectRequest; public class CopyObject { public static void main(String[] args) { String accessPointArn = "*** access point ARN ***"; String sourceKey = "*** Source object key ***"; String destinationKey = "*** Destination object key ***"; 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(); // Copy the object into a new object in the same bucket. CopyObjectRequest copyObjectRequest = new CopyObjectRequest(accessPointArn, sourceKey, accessPointArn, destinationKey); s3Client.copyObject(copyObjectRequest); } 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(); } } }