S3 Copy Files between Accounts

MD
R
Markdown

Recipe to copy files between AWS S3 different Accounts

  1. Source Account 1.1 Create a Policy and attach to a service account user { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:GetObject" ], "Resource": [ "arn:aws:s3:::spacex", "arn:aws:s3:::spacex/" ] }, { "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:PutObject", "s3:PutObjectAcl" ], "Resource": [ "arn:aws:s3:::nasa", "arn:aws:s3:::nasa/" ] } ] }

  2. On the destination bucket, add a policy allowing source bucket owner to write on this destination bucket

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Only allow writes to my bucket with bucket owner full control",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::99999999999:user/super-user"
            },
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::nasa",
                "arn:aws:s3:::nasa/*"
            ],
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control"
                }
            }
        }
    ]
}
  1. Run the command aws s3 cp s3://spacex s3://nasa --acl bucket-owner-full-control --recursive

Created on 2/9/2021