將物件複製到 Snowball Edge 上 Snowball Edge 儲存貯體上的 Amazon S3 相容儲存體 - AWS Snowball 邊緣 開發人員指南

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

將物件複製到 Snowball Edge 上 Snowball Edge 儲存貯體上的 Amazon S3 相容儲存體

下列範例會將名為 sample-object.xml 的檔案上傳至 Snowball Edge 儲存貯體上的 Amazon S3 相容儲存體,而您擁有使用 的寫入許可 AWS CLI。若要使用此命令,請以您自己的資訊取代每個 使用者輸入預留位置。

aws s3api put-object --bucket sample-bucket --key sample-object.xml --body sample-object.xml --endpoint-url s3api-endpoint-ip --profile your-profile

下列 Snowball Edge 上的 Amazon S3 相容儲存體範例會使用適用於 Java 的 開發套件,將物件複製到相同儲存貯體中的新物件。若要使用此命令,請以您自己的資訊取代每個 使用者輸入預留位置。

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; add : import java.io.IOException; public class CopyObject { public static void main(String[] args) { String bucketName = "*** Bucket name ***"; 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(sourceKey, destinationKey); s3Client.copyObject(copyObjectRequest); CopyObjectRequest copyObjectRequest = CopyObjectRequest.builder() .sourceKey(sourceKey) .destinationKey(destKey) .build(); } 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(); } } }