I was moving AWS resources from one account to separate staging and production accounts. One of the steps was to migrate S3 buckets. A solution was cross account replication. Because S3 cross region replication moves only new files we have to create a S3 Batch Operation to move existing objects.
S3 cross account replication and Batch Operation
As following:
- enable S3 bucket versioning on your buckets,
- in source account prepare an IAM policy as a part of an IAM role to be used by the S3 replication:
- in source account create an IAM role that includes above policy (trusted entity type = AWS service, Use case = S3),
- in source account prepare an IAM role for a S3 Batch Operation (trusted entity type = AWS service, Use case = S3 Batch Operations):
- in target account update S3 bucket policy:
- go to your source S3 bucket, then "Management" bookmark and click on "Create replication rule":
- give a name,
- status = "Enabled",
- role scope = "Apply to all objects in the bucket",
- choose your destination bucket (mark "Change object ownership to destination bucket owner"),
- choose your S3 replication IAM role,
- mark "Change the storage class for the replicated objects with Standard storage class",
- mark "Delete marker replication" as a additional replication option,
- in your account go to "S3", open "Batch Operations" and push "Create job":
- object list = "Generate an object list based on a replication configuration" (it will check S3 replication rule we created previously),
- choose your source S3 bucket,
- click "Next",
- operation = "Replicate",
- click "Next",
- put a name,
- unmark "Generate completion report",
- choose your S3 Batch Operations IAM role,
- click "Next",
- check settings and click "Submit".