Last active
July 8, 2022 06:28
-
-
Save taufiqpsumarna/c3e93ff0fd4b96cf8f81417c7f678262 to your computer and use it in GitHub Desktop.
This Gist Show How To Migrate S3 To Another Account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Source Policy IAM | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"s3:ListBucket", | |
"s3:GetObject" | |
], | |
"Resource": [ | |
"arn:aws:s3:::SOURCE_BUCKET", | |
"arn:aws:s3:::SOURCE_BUCKET/*" | |
] | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"s3:ListBucket", | |
"s3:PutObject", | |
"s3:PutObjectAcl" | |
], | |
"Resource": [ | |
"arn:aws:s3:::DESTINATION_BUCKET", | |
"arn:aws:s3:::DESTINATION_BUCKET/*" | |
] | |
} | |
] | |
} | |
### Destination Bucket Policy | |
{ | |
"Version": "2012-10-17", | |
"Id": "Policy1611277539797", | |
"Statement": [ | |
{ | |
"Sid": "Stmt1611277535086", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "arn:aws:iam::AWS_ACCOUNT_NUMBER:root" #change with | |
}, | |
"Action": "s3:PutObject", | |
"Resource": "arn:aws:s3:::DESTINATION_BUCKET/*", | |
"Condition": { | |
"StringEquals": { | |
"s3:x-amz-acl": "bucket-owner-full-control" | |
} | |
} | |
}, | |
{ | |
"Sid": "Stmt1611277877767", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "arn:aws:iam::AWS_ACCOUNT_NUMBER:root" | |
}, | |
"Action": "s3:ListBucket", | |
"Resource": "arn:aws:s3:::DESTINATION_BUCKET/" | |
} | |
] | |
} | |
### Configure aws cli with source IAM | |
aws configure --profile migrates3 | |
### S3 Command To Copy Content | |
aws s3 cp s3://source-DOC-EXAMPLE-BUCKET/object.txt s3://destination-DOC-EXAMPLE-BUCKET/object.txt --acl bucket-owner-full-control --profile migrates3 | |
Source: | |
https://aws.amazon.com/premiumsupport/knowledge-center/copy-s3-objects-account/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment