How to copy S3 objects between AWS accounts

0 min read 106 words

In your source account create a customer-managed policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::source-EXAMPLE-BUCKET",
                "arn:aws:s3:::source-EXAMPLE-BUCKET/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::destination-EXAMPLE-BUCKET",
                "arn:aws:s3:::destination-EXAMPLE-BUCKET/*"
            ]
        }
    ]
}

In your destination bucket, update the bucket policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::1234567890:user/Andrew"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::destination-EXAMPLE-BUCKET/*",
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control"
                }
            }
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::1234567890:user/Andrew"
            },
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::destination-EXAMPLE-BUCKET"
        }
    ]
}

Testing the S3 copy between accounts:

aws s3 cp s3://source-EXAMPLE-BUCKET/object.txt s3://destination-EXAMPLE-BUCKET/object.txt --acl bucket-owner-full-control
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags