Ishank Gupta

  • About Me
✕

Copy Amazon S3 bucket from one account to another

Programming

Ishank Gupta April 14, 2019

Step 1: Create a policy in the source S3 bucket by clicking on S3 Bucket -> Permissions -> Bucket Policy.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "DelegateS3Access",
            "Effect": "Allow",
            "Principal": {
                "AWS": "<%= you destination account id %>"
            },
            "Action": [
                "s3:ListBucket",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::<%= your source bucket name %>/*",
                "arn:aws:s3:::<%= your source bucket name %>"
            ]
        }
    ]
}

Step 2: Create S3 bucket in your destination AWS account.

Step 2: Create another policy in your destination AWS account by clicking on the following link https://console.aws.amazon.com/iam/home. Select policy on the left sidebar and then click Create Policy. Select JSON tab and paste the policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::<%= your source bucket name %>",
                "arn:aws:s3:::<%= your source bucket name %>/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::<%= your destination bucket name %>",
                "arn:aws:s3:::<%= your destination bucket name %>/*"
            ]
        }
    ]
}

Step 4: Install AWS cli on your local machine and then login using aws configure.

Step 5: Run the command which will copy the bucket from source to destination i.e. aws s3 sync s3://sourcebucket s3://destinationcucket, it will take some time based on the number of files in your bucket.

Author: Ishank Gupta

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest Posts

Copy Amazon S3 bucket from one account to another

Recent Posts

  • Copy Amazon S3 bucket from one account to another
Copyright © 2019 - IshankGupta.com.