Table of Contents
There are times when we just want more speed as well as redundancy of data stored in an S3 bucket. This is where the “cross region replication on S3 ” comes.
Question: What is actually “cross region replication“?
Answer: In short, it is nothing but creating multiple copies of data stored in an S3 bucket, which can be helpful in case of disaster recovery and high availability.
From the picture above, you can see that the bucket stored in “America = S3 bucket 2” is being replicated in the “Asia = S3 bucket 1” for high availability and redundant data.
Note: For enabling cross region replication on an S3 bucket, versioning must be enabled on the bucket.
Before going further, make sure you know -> How to create an S3 bucket
Also -> How to enable versioning on an S3 bucket
Step 1: Create an S3 bucket
In this, we have already created a bucket with the name “versioning-geekylane“, as shown in the picture below.
Moreover, you can notice that the “objects can be public” in this bucket.
Step 2: Add a cross region replication rule
For this, we have to go under the “Management” section of the “versioning-bucket” and after that, we have to go to “Replication” tab and from there select “+ Add rule” in order to add a cross region replication rule.
Step 3: Set Source Bucket
In this, we will be specifying which bucket we want to create a replication of, we are using “versioning-geekylane” as the source bucket, for reference check image below. After that click on the “Next” icon.
Step 4: Set Destination Bucket
Now, in this step, we have to specify in which bucket we want to save/copy the contents/objects of “versioning-geekylane” bucket.
Simply click on the “Create new bucket“.
We are going to create a new destination bucket, with a name “geekylane-crr” in the “Region = Asia Pacific (Mumbai)“, for reference check the screenshot below.
After that, click on “Next” icon.
Step 5: Set an IAM role
Here, we are going to create a new IAM rule for the cross region replication rule, the name of the “rule = geekylane-crr-rule” after that tick on the “Enabled” icon as shown below and click on “Next” icon.
Step 6: Review the cross region replication rule
Before saving the changes being made to the rule, review them and then click on the “Save” icon.
Step 7: Cross region replication is created
From the screenshot below, we can confirm that our crr rule has been created successfully.
Step 8: Both the buckets are available – s3 cross region replication in multiple regions
From the image below, you can see that:
- Source Bucket = versioning-geekylane (US East (N. Virginia)
- Destination Bucket = Asia Pacific (Mumbai)
Both the buckets are situated in different regions.
Step 9: Check the Destination Bucket
Question: Wait! what? Why is the destination bucket empty?
Answer: It is because the cross region replication rule is only going to apply on the newly created files and not for already present files.
Step 10: We are going to create a file
Note: We are using the file which we have used in the -> How to enable versioning on an S3 bucket
And this is going to be the “version 3” of the “geekylane.txt“, and have the following contents.
Step 11: Upload a file to Source bucket
In this, we are going to upload a file, which we have created in the “Step 10“, for reference check the image below.
After uploading the file, you will see a “100% Successful” message at the bottom of your S3 dashboard.
Step 12: Check the Destination bucket
From below, we can see that the “geekylane.txt” file has bee replicated (copied) from the “versioning-geekylane” bucket to -> “geekylane-crr” bucket.
Step 13: Try to access the file
We are still getting an ERROR on accessing the “geekylane.txt” using the Object URL from Browser.
Question: Why is that? What is happening?
Answer: Only the contents are being copied from “Source to -> Destination” bucket, and not the “Bucket Policies” and “Access Control List“.
Step 14: Make the file/object in the destination bucket public
In this, we are going to give the public access to the file “geekylane.txt” which is being copied from the source bucket.
To do so, follow the image below.
Step 15: Access the file Again
Now, the file “geekylane.txt” can be easily accessible from the “web browser” and do note that file is stored in the “destination bucket = geekylane-crr“.
Question: Does deleting a file from the “Source bucket = versioning-geekylane” is going to delete the file from “Destination bucket = geekylane-crr“?
Answer: No, by default on the new file/object creations are going to be replication and not anything else and not even the deletion. The file is deleted from the “source” is not going be deleted from “destination“.
Step 16: Delete file from Source bucket
Delete the “geekylane.txt” file from the “source bucket = versioning-geekylane“.
From the picture below, we can confirm that the latest version of the “geekylane.txt” file is being deleted from the “Source bucket = versioning-bucket“.
Step 17: Check the Destination bucket
From the contents of the “Destination bucket = geekylane-crr“, we can confirm that the latest version of the “geekylane.txt” is still available in it.
Step 18: Access “geekylane.txt” from both the buckets
From the image below, we can see that the “Destination bucket = geekylane-crr” is still showing the latest version (version 3) of the “geekylane.txt” but the “Source bucket = versioning-geekylane” is now showing the version 2 of the “geekylane.txt” file.
Which, as conclusion states that the deletion of objects stored in an S3 bucket is not going to be replication from the source bucket to the destination bucket if the cross region replication is enabled on s3 bucket.
More on S3:
More on AWS:
- How to set up IAM on AWS account? (Complete Step by Step Guide)
- One click WordPress set up with docker and docker-compose (local, live, cloud) (without SSL)
- Set-up a Nginx web server on ubuntu 18.04 EC2 Instance AWS
Comment here