How to add a replication rule to an S3 bucket

Replication is the auto-coping of S3 objects from one S3 Bucket to another S3 Bucket in the same region or in a different AWS region. Replication can copy newly created or updated objects from the source S3 bucket to the destination S3 bucket. The objects which already exist in the bucket are not copied using replication.
Before the replication rule is created to copy objects, versioning of the S3 bucket must be enabled on both the source and the destination S3 bucket. The objects which are copied in the destination bucket are the exact copy of the source objects, i.e. the copied objects have the same key names and the same metadata. The metadata can be creation time, owner, user-defined metadata, version ID, access control list (ACL), and storage class.

In this article, I will show you the steps to create a replication rule to copy objects to/from the existing buckets.

Pre-requisites

  1. AWS Account (Create if you don’t have one).
  2. S3 Bucket (Click here to learn to create an S3 bucket)

What will we do?

  1. Login to AWS.
  2. Add a replication rule to an S3 Bucket

Login to AWS

Click here to go to AWS Login Page.

When we hit the above link, we will see a web page as follows where we are required to log in using our login details.

Login page

Once you log in, you see the AWS Management Console as follows.

AWS console

Add a replication rule to an S3 Bucket

Before we create a replication rule, let's go to the S3 console. 

Search for "S3" and click on the result you get as shown in the following image.

Search S3 service

You can see the existing S3 buckets in your account on the S3 console. 

To create a replication rule, we will use "rahul-test-delete" as the source S3 bucket and "rahul-test-delete2" as the destination S3 buckets.

Upon creating a replication rule, objects will be copied from "rahul-test-delete" to "rahul-test-delete2".

You can choose any buckets you have with versioning enabled on them.

Click on the source bucket, here it is "rahul-test-delete".

S3 main dashboard

Click on the "Management" tab --> Replication -- > and then "Add rule".

Management tab in S3 bucket

When you click on "Add rule", you will see the screen as follows. Choose "Entire bucket" and click on "Next".

Replication rule - set source

Here, choose the "Destination bucket", here it is "rahul-test-delete2".

Since this bucker does not have versioning enabled, click on "Enable versioning" which will enable versioning on your destination bucket.

Replication rule - set destination

Now, click on "Next".

Replication rule - set destination

If you want to enable S3 Replication Time Control (S3 RTC) in your replication configuration, check the S3 Replication Time Control check box. S3 RTC replicates most objects within 15 minutes of their upload. To know more about S3 Replication Time Control (S3 RTC) click here to go to the official AWS documentation.

Click on "Next".

Replication rule - set destination

Here, give a name to the replication rule, this will also create a new IAM Role which S3 can assume to replicate objects on your behalf. 

By default the status is "Enabled", you can disable it if you do not want to enable the replication rule. Here, we have kept it as "Enabled".

Click on "Next" to proceed. 

Replication rule - configure rule options

Before you save the rule, review the configurations you made and then click on "Save".

If you want to change any of the configurations, click on Edit.

Replication rule - review

Once the rule is saved, you can see it under the Replication tab.

Successful replication rule creation

Now, if you go to your source  S3 bucket and upload a few new objects, you can see these new objects replicated to the destination bucket. Here, the objects which already existed before the replication rule was created will not get copied or replicated to the destination bucket.

Here, we have uploaded a file named "new-file-to-test-replication.rtf"

Upload a new file in the source S3 bucket

Now, go to the destination S3 bucket and see the objects copied to it. 

Here, we can see that the file named "new-file-to-test-replication.rtf" got replicated.

Replicated the file in the destination bucket

Now, if you no longer need the replication rule, go to the source S3 bucket and under Management -- > Replication tab, select the rule and click on delete to delete the rule permanently.

Select the replication rule for deletion

Click on the "Confirm" button to proceed with the replication rule deletion.

Delete the rule

Conclusion

In this article, we saw the steps to create a Replication Rule to copy objects from the source S3 Bucket to the destination Bucket. We saw new objects in the source S3 Bucket getting copied to the destination S3 Bucket. We also saw the steps to delete the rule when you no longer need it. 

Share this page:

0 Comment(s)