The dest user need to be able to create user policies
cp credentials{.sample,}
cp new_bucket_policy.json{.sample,}
cp new_user_policy.json{.sample,}
Get the dest user's account ID and put it in new_bucket_policy.json
(it's the account number in AWS Management Console)
Set the aws_access_key_id
and aws_secret_access_key
in the credentials
file
Replace SRC_BUCKET_NAME
and DEST_BUCKET_NAME
in the json files
AWS_CONFIG_FILE=credentials aws --profile src s3api get-bucket-policy --bucket SRC_BUCKET_NAME --query Policy --output text > old_bucket_policy.json
AWS_CONFIG_FILE=credentials aws --profile src s3api put-bucket-policy --bucket SRC_BUCKET_NAME --policy file://new_bucket_policy.json
AWS_CONFIG_FILE=credentials aws --profile dest iam put-user-policy --user-name DEST_USERNAME --policy-name MigrateBucketPolicy --policy-document file://new_user_policy.json
AWS_CONFIG_FILE=credentials aws --profile dest s3 sync s3://SRC_BUCKET_NAME s3://DEST_BUCKET_NAME
☑️ Done
AWS_CONFIG_FILE=credentials aws --profile src s3api put-bucket-policy --bucket SRC_BUCKET_NAME --policy file://old_bucket_policy.json