Cross-region replication (CRR) enables automatic, asynchronous copying of objects across buckets in different AWS Regions. Buckets configured for cross-region replication can be owned by the same AWS account or by different accounts.
Prerequisites of setting up cross-region replication
- The source and destination buckets must be in different AWS Regions.
- Both source and destination buckets must have versioning enabled.
- Amazon S3 must have permissions to replicate objects from the source bucket to the destination bucket on your behalf.
Bucket testcrossregionrep is present in us-east-1 (Northern Virginia) region while bucket crossreplicationbuck2 is present in ap-south-1 (Mumbai) region.
Bucket testcrossregionrep is set up to cross-region replicate to bucket crossreplicationbuck2. Now if you store a file in bucket testcrossregionrep, that file will automatically be copied to the bucket crossreplicationbuck2.
Facts about Cross-region replication
- Objects that existed before you added the replication configuration to the bucket are not replicated.
- Amazon S3 creates delete markers for expired objects, but it does not replicate delete markers.
- We can replicate objects from a source bucket to only one destination bucket. After Amazon S3 replicates an object, the object can’t be replicated again.
S3 Cross Region Replication Lab
- Create a S3 Bucket in us-east-1 (Northern Virginia) region with name ‘testcrossregionrep’
2. Enable versioning for bucket testcrossregionrep
3. Upload two versions of file helloworld.txt in bucket testcrossregionrep
4. Click on the Management tab, select Replication and click on the Add Rule button.
5. We would like to set the entire bucket as the source so leave the default settings and click Next.
6. Let us create a new bucket ‘crossreplicationbuck2′ in ap-south-1 (Mumbai) region where we want to replicate.Click on create new bucket option.
7. Provide the desired bucket name (here: crossreplicationbuck2) and select the region ( here:Mumbai)
8. Now we have to grant S3 permissions to replicate objects. Just select Create new role in the IAM role field and give a name to your rule. Make sure enabled is selected and click Next.
9. Review your Replication rule and click Save to enable cross-region replication.
Now we have setup the cross region replication for S3 and summary is as below.
Now test the replication by uploading a file to your source bucket. When it’s done uploading, you should see the same file in your destination bucket.
Upload new version of file helloworld.txt in bucket testcrossregionrep
Navigate to bucket crossreplicationbuck2 and verify that the object is being replicated.
For large objects to replicate, it can take several hours. Although it might take a while before a replica is available in the destination bucket, it takes the same amount of time to create the replica as it took to create the corresponding object in the source bucket.