Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3Client copyObject cross regiond

I'm trying to copy files between 2 S3 buckets on different regions:

US_EAST_1 ---> EU_CENTRAL_1

Using the following command:

s3client.copyObject(sourceBucket, sourceFile, DestBucket, DestFile);

I initiate the s3client without providing a region to allow it to work with both regions, but I'm getting the following error:

Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: C2E6D084FF257437), S3 Extended Request ID: rXDTuqPSCCKWoF8luScpL+/po93oEQC2VSNUBQtSLBh5q8yEAO0WwK8FnBMPGEZQjS+zwkkHWBg= at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1305) at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:852) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:630) at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:405) at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:367) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:318) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3787) at com.amazonaws.services.s3.AmazonS3Client.copyObject(AmazonS3Client.java:1530) at com.amazonaws.services.s3.AmazonS3Client.copyObject(AmazonS3Client.java:1487)

I'm using 'aws-java-sdk' version: '1.11.7'

How to overcome this error?

like image 792
Roee Gavirel Avatar asked Jun 14 '16 15:06

Roee Gavirel


1 Answers

The client cannot be configured to "work in both regions". It must be configured with a region so it works in a single region.

When copying objects between buckets (between regions), set the client to the target region. Then, specify the source and target buckets.

like image 61
Matt Houser Avatar answered Oct 12 '22 19:10

Matt Houser