My current plan to move an S3 bucket from AWS region us-west-1
to AWS region us-west-2
while keeping the same bucket name seems highly inefficient as it's copying the entire bucket twice:
# Create new bucket in us-west-2
aws s3 mb s3://temp-bucket --region us-west-2
# Copy files from old to new bucket in us-west-2
aws s3 sync s3://my-bucket s3://temp-bucket --source-region us-west-1 --region us-west-2
# Delete the old bucket in us-west-1
aws s3 rb --force s3://my-bucket
# Create new bucket in us-west-2
aws s3 mb s3://my-bucket --region us-west-2
# Copy files from old to new bucket
aws s3 sync s3://temp-bucket s3://new-bucket
How can I efficiently move an S3 bucket to a new AWS region while keeping the same bucket name?
You can't. To add insult to injury you also can't rename a bucket, and can take up to 24 hours for your old bucket name to be available for re-use.
There is a slight alternative to what you've got there, which is rather than running AWS CLI commands you could set up cross-region replication between the buckets. Get everything into the us-west-2 bucket, start using that on a temporary basis. Remove the us-east-1 bucket, wait 24 hours, re-create the bucket in us-west-2, and use same-region replication to get it all into the new bucket.
This removes the possibility of an interruption to your local CLI session stopping the replication, and keeps the bucket up to date constantly until you remove the old buckets. I suggest doing a quick lookover of the costs involved in setting this up.
One alternative is to use the AWS console to initiate the file transfers:
One still needs to create a new bucket twice, but the copy is rather fast:
Note that moving data between different AWS region incurs a cost.