Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to programatically transfer files stored on amazon s3 from one region to another?

Tags:

java

amazon-s3

Does anybody know is it possible to programatically transfer files stored on amazon s3 from one region to another?

like image 864
aviad Avatar asked Oct 12 '22 13:10

aviad


1 Answers

This is easily accomplished using the Amazon S3 API to copy the object from one bucket to another. It doesn't matter that the buckets are in different regions.

Here's an example using the Rest API.

PUT /jetsam HTTP/1.1
Host: atlantic.s3.amazonaws.com
x-amz-copy-source: /pacific/flotsam
Authorization: AWS 15B4D3461F177624206A:ENoSbxYByFA0UGLZUqJN5EUnLDg=
Date: Wed, 20 Feb 2008 22:12:21 +0000

Or if you prefer, the SDKs can do the same thing. Here's a .Net SDK example.

static AmazonS3 client;
client = Amazon.AWSClientFactory.CreateAmazonS3Client(
                    accessKeyID, secretAccessKeyID);

CopyObjectRequest request = new CopyObjectRequest();
request.SourceBucket = bucketName;
request.SourceKey = keyName;
request.DestinationBucket = bucketName;
request.DestinationKey = destKeyName;
S3Response response = client.CopyObject(request);

If you mean that you want to change a buckets region, you would have to:

  • Copy the objects to a new bucket
  • Delete the old bucket
  • Recreate the bucket in the new region
  • Copy the objects back into the new bucket.

Of course most of the major S3 GUI tools can also copy objects between buckets and regions too.

like image 184
Geoff Appleford Avatar answered Oct 15 '22 09:10

Geoff Appleford