Kunal Yadav

Product Engineer who loves to read books and learn about Computer Science.

Backing up your files using S3 Cross Region Replication

Hello Everyone, in this article we are going to discuss the benefits of S3’s cross-region replication.

As you may already know from our previous discussion that S3 stores data by making copies across multiple availability zones in a single region.

In cross-region replication, the data stored in a bucket is replicated automatically and asynchronously across a bucket in a different region.

For example — Let’s say you have two buckets A and B. Bucket A is present in us-east-1 (Northern Virginia) region while bucket B is present in ap-south-1 (Mumbai) region. 
Bucket A is set up to cross-region replicate to bucket B. Now if you store a file in bucket A, that file will automatically be copied to the bucket B.

Cross-region replication can be used to back up your data in another region.

Conditions for enabling Cross-region replication

  1. Versioning must be enabled on both the source and destination buckets.
  2. Regions must be unique.
  3. Amazon S3 must have permissions to replicate objects from the source bucket to the destination bucket on your behalf.

Facts about Cross-region replication

  1. Files in an existing bucket are not replicated automatically but all the subsequent updated files will be automatically replicated.
  2. You cannot replicate to multiple buckets or use daisy chaining (from bucket A to bucket B to bucket C).
  3. Delete markers are replicated.
  4. Deleting individual versions or delete markers will not be replicated.

What is Versioning?
If you store multiple objects with the same name, that object is overwritten and you only get the latest object.

When versioning is enabled multiple versions of the object with the same name are created. This can be used to prevent accidental overwriting of objects.

What are delete markers?
When you delete an object in a versioning enabled bucket, that object is not deleted from the bucket, but instead, a delete marker is created.

You can use this delete marker to recover the deleted object. Once you delete this delete marker, that object cannot be recovered.

Let’s get Practical

Now it’s time to see cross-region replication in action. Login to your AWS console and click on S3.

1. Create two buckets in different regions. Here I am creating the source bucket jca-source in the US East (N. Virginia) region and destination bucket jca-destination in the Asia Pacific (Mumbai) region.
You can choose any regions you want but they must be different.

2. Select the source bucket, click on properties tab and enable versioning.

3. Click on the Management tab, select Replication and click on the Add Rule button.

4. We would like to set the entire bucket as the source so leave the default settings and click Next. Now select your destination bucket, since we have not enabled versioning on the destination bucket yet we see the Enable Versioning button. Click on it and click Next.
You can also see that at this point you have the option to change the storage class for the replicated objects. You can optimize your costs by choosing the option most appropriate for your use case, but here I am leaving it unchecked.

5. Now you have to give 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.

6. Review your Replication rule and click Save to enable cross-region replication.

Now, you can test your cross-region replication. Upload a file to your source bucket. When it’s done uploading, you should see the same file in your destination bucket.

I hope you got something better out of this article.

If you liked it, please give a few claps so it reaches more people who would love it!

More by Kunal Yadav

Topics of interest

More Related Stories