Cross-Region replication feature enables asynchronous automatic replication of copying objects between two AWS regions. You need to enable this feature on bucket level and configure on source bucket. This feature allows you to either select the whole source or subset of an object to replicate on destination region.
Important things to keep in mind:
· Cross-region will not work if versioning feature is not enabled on the bucket
· You cannot replicate bucket within the same region and hence it must be between two different regions
· Existing files within in the bucket are not replicated, when enabled cross-region feature. All the objects and subset which are created post enabling cross-region replication will be replicated.
· You cannot replicate the S3 bucket to the third region
· Objects which are marked as deleted are also replicated
Let’s do the LAB, we will create two S3 bucket called apmumbucket (source in Asia Pacific India region) & apsgbucket (destination in Asia Pacific Singapore region) and using the cross-region replication feature will replicate the object.
Go to the Amazon S3 console and create a new bucket
Create a bucket called apmumbucket and select the region Asia Pacific (Mumbai)
Versioning is must and hence we will enable it and proceed further
Enabling read permission here is not mandatory but just to access from internet I am selecting read permission, you can ignore this option
Review the settings and click on create bucket
Let us upload one file
Observe the file is uploaded in the bucket called apmumbucket
Let us now create another bucket in Singapore region where we want to replicate the content from Mumbai Region. Just review the summary as I am creating a bucket called apsgbucket
Now we can see both the buckets are created in cross-region (Mumbai & Singapore) & let’s enable the feature
Go to the bucket property of apmumbucket which is our source and look for the option cross-region replication
Enable it and verify the below settings:
· Source – Select Asia Pacific (Mumbai)
o Whole Bucket – Under this bucket we have the option to select the whole or sub buckets if available. We will select whole bucket
· Destination – Select Asia Pacific (Singapore)
o Bucket name – The bucket in which you want to replicate. We will select the one which we created apsgbucket
· Destination Storage Class – Type of storage class what we learned in previous article. Since this is the secondary or replica copy we will select infrequent access class.
· Role – Either it will create by default one for you or we can create our own. Will leave the default settings.
You can select other than whole bucket
You have the option to select different storage class
Now the cross-region replication is enabled
Let us see now if we can see anything under the bucket apsgbucket as we have uploaded one file as mentioned above. Any object prior to enabling the cross-region feature isn’t replicated.
Let us know try to upload a new file in bucket apmumbucket and see if it replicates on the bucket apsgbucket
Verify the settings and upload
File upload is successful in bucket apmumbucket, let us now quickly go to the bucket apsgbucket to see if the file is replicate or not.
The file now is automatically replicated
Also there is only one version of the file. Now let us download the file from bucket apmumbucket (APAC Mumbai region) and modify the content and upload another version. We will see if that is replicated too in Singapore region bucket
There is a file name called test file.txt, download the file and modify it. Save it and again upload it to the bucket apmumbucket
We see there are now two versions for the file test file.txt
Notice the same file replicate with the latest versions too 😀