Skip to content

Instantly share code, notes, and snippets.

@alanwill
Created December 5, 2015 20:27
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save alanwill/31c3232049eeaae14b23 to your computer and use it in GitHub Desktop.
Save alanwill/31c3232049eeaae14b23 to your computer and use it in GitHub Desktop.
Move an S3 bucket to a different region
aws s3 sync s3://oldbucket s3://newbucket --source-region us-west-1 --region us-west-2
@vandanapoddar
Copy link

I want to literally "move" a bucket from one region to another. The bucket name and contents should be same. Above command does not work when oldbucket and newbucket are same. It simply does nothing in that case. Am I going wrong somewhere?

@FernandoMiguel
Copy link

@vandanapoddar you probably found it by now, but bucket names are globally unique.
so your option is to copy the data to a temp bucket, delete the original one, create the new one in the new region and move data again.
keep in mind the cost of transferring between regions

@mvmn
Copy link

mvmn commented Apr 19, 2017

The problem is also that you can't delete bucket and create new one with same name right away - Amazon caches these, and thus it takes a while until bucket name becomes available again:

After a bucket is deleted, the name becomes available to reuse, but the name might not be available for you to reuse for various reasons. For example, it might take some time before the name can be reused

http://docs.aws.amazon.com/AmazonS3/latest/UG/DeletingaBucket.html

@dgeske
Copy link

dgeske commented Jun 20, 2017

To simplify the synchronization of data from one S3 bucket to another, please take a look at the sync-buckets-state-machine project on awslabs:

A sample AWS Step Functions (SFN) state machine, designed to one-way synchronize an Amazon S3 source bucket into another S3 destination bucket.

@MartinThoma
Copy link

MartinThoma commented Apr 6, 2018

Move a foobucket from us-west-1 to us-west-2

-- Create tmpbucket
$ aws s3 sync s3://foobucket s3://tmpbucket --source-region us-west-1 --region us-west-2
$ aws s3 rb s3://foobucket --force
-- Recreate foobucket in us-west-2, but you might have to wait due to caching
$ aws s3 sync s3://tmpbucket s3://foobucket --source-region us-west-2 --region us-west-2

@drnic
Copy link

drnic commented Jan 15, 2021

Remember to copy over any CORS permissions etc too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment