In this guide , We will see how to setup s3 cross region replication .
- Replication enables automatic, asynchronous copying of objects across Amazon S3 buckets.
- Buckets that are configured for object replication can be owned by the same AWS account or by different accounts.
- You can copy objects between different AWS Regions or within the same Region.
- Destination bucket in a different region where you want to replicate objects.
- An IAM role So that S3 can take care of the replication process by itself.
Types Of Replication:
- SAME REGION REPLICATION: The source and destination buckets will be in the same region and the S3 objects are copied within the region.
- CROSS REGION REPLICATION: It is used to copy across the S3 buckets in the different AWS Region.
Requirements For Replication:
- versioning should be enabled in both the source and the destination buckets.
- Amazon S3 must have the permission to copy the objects from one region to another.
- The source bucket owner must have the source and destination AWS Regions enabled for their account. The destination bucket owner must have the destination Region-enabled for their account.
- If the source bucket has Amazon S3 object lock enabled, the destination bucket must also have object lock enabled.
- If the owner of the source bucket doesn’t own the object in the bucket, the object owner must grant the bucket owner READ and READ_ACP permissions with the object access control list.
CROSS REGION REPLICATION:
Cross region replication enables automatic, asynchronous copying of objects across Amazon S3 buckets.
Once the cross-region replication is enabled , Any new objects in the source bucket will be automatically copied to the destination bucket.
The objects stored in the destination bucket will have the same object name and the meta data.
Replication is not transitive , which means , Lets say you have 3 buckets BA , BB , BC and you setup replication between BA and BB , BB and BC.Any objects uploaded to BA will only be replicated to BB only.
Any objects in the source bucket that was available before configuring the cross-region replication will not be replication to destination bucket.
If you want those objects in the destination bucket , We must use command line tools like s3cmd or aws cli to copy the objects manually.
Lets start by creating two buckets in different regions,
For this tutorial , I am creating 1 bucket in Singapore region and 1 bucket in Mumbai region and We are going to setup cross region replication from Singapore to Mumbai region.
Login to S3 console,
Choose Create bucket , name of the bucket is globally unique , Give a Bucket name and click Next
Versioning should be enabled and click Next,
For security concerns , Block all public access to S3 bucket.
Review all the configurations and click Create bucket.
Repeat the same process and create a S3 bucket in different region.
For this tutorial , I am going to create a destination bucket in Mumbai region.
Don’t forget to change the Region,
Make sure versioning is enabled.
Now we have 2 bucket in different region (Singapore and Mumbai) with Versioning enabled.
If you already have buckets , You can enable versioning as shown below,
Select the bucket in the S3 console , Choose Properties,
Click Versioning , Enable versioning and click Save.
Lets setup Cross region replication from Singapore to Mumbai region. To do so ,
Choose the source S3 bucket ,
Click Management and then Replication,
Click Add rule ,
You can choose to replicate the entire objects or particular folder (prefix) in S3 bucket.
And If you have objects encrypted at rest using KMS in a S3 bucket , You can select it and click Next,
When choosing destination bucket , You have two options , It will ask whether the destination bucket is in same account or in different account.
In the Next page , You need to setup IAM role for the source bucket to have replicate permissions.
Click Create New role , a give a name for the role. If you have an IAM role already present , you can use it.
Review all the configurations and click Save.
Now that we have configured cross region replication between buckets.
if you upload any files to the source bucket will be automatically replicated to Destination bucket.Lets test the same.
Select the source bucket , Click Upload,
Click Add files,
Once the files are uploaded in the Source bucket , Lets go and check the Destination bucket.
And you can see that all the files are automatically copied to Destination bucket.
Hope this article helped you to setup cross region replication So that you can have the backup of all the files in different region.
Thanks for reading this article , Please do check out my other publications.