Duncan McClean

Move S3 objects from one AWS account to another

11th April 2020

I'm in the process of moving all of my AWS stuff into it's own account, separated from my online shopping account. It's a process that has to be done manually as AWS don't have an easy way of moving resources between accounts.

Anyway, to stop you trolling through Amazon's horrible documentation to get this ugly job done. Here's some simple instructions on moving files between buckets and AWS accounts.

  1. In the AWS account you want to move stuff to, create a new bucket, sadly it'll need a unique name that's not used by your current bucket.

  2. Get the AWS account ID of your new AWS account (the one you wish to move stuff to). You can find it in your 'My Account' page.

  3. Update the bucket policy in the old bucket (old AWS account) to this. Replace ACCOUNT_ID with your new AWS account's ID and replace awsexamplesourcebucket with the name of the old bucket.

json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DelegateS3Access",
"Effect": "Allow",
"Principal": {"AWS": "ACCOUNT_ID"},
"Action": ["s3:ListBucket","s3:GetObject"],
"Resource": [
"arn:aws:s3:::awsexamplesourcebucket/*",
"arn:aws:s3:::awsexamplesourcebucket"
]
}
]
}
  1. Then you'll want to install the AWS CLI, if you haven't already and configure it for your new AWS account.

  2. Then you should be able to run the following command, replacing the obvious. If you did everything right, that command should copy everything over to your new bucket.

aws s3 sync s3://old-bucket-name s3://new-bucket-name --copy-props