S3 Bucket Lifecyle And Replication Rules

In the previous article, we learned about hosting a static website on S3 along with creating an IAM user and some CLI commands.
 
In this article we will be learning a few more interesting topics as mentioned below,
  • Setting up Lifecycle rule for S3 bucket
  • Setting up Replication rule for S3 bucket
We have learned about the different storage lifecycles in one of the other articles on S3. So here we will actually set up and see how the storage type changes as per the rules we define.
 

SETTING UP LIFECYCLE RULE FOR S3 BUCKET

 
So, let’s set up some lifecycle rules.
 
To do so, go to the bucket management tab and click on create lifecycle rule.
 
While creating a rule we can also consider that whether we want to transition the current version or the previous version of data depending on the versioning for the bucket.
 
 
We have for now chosen only the current version for the transition and have selected the expiration rule also in order to define when our objects will be expired.
 
The below diagram depicts different storage lifecycles and their transition depending on the days we have configured.
 
 
We can see that we are transitioning our data in the bucket to Standard-Infrequent Access after 30 days and similarly so on for other storage types.
 
So after 365 days, the data will be deleted. Generally, we set up such rules for logs.
 
 
We can see our lifecycle rule has been created successfully. So, that’s how we can set lifecycle rules.
 
Now next is to set up the replication.
 

SETTING UP REPLICATION RULE FOR S3 BUCKET

 
As we have already set up the lifecycle rule, so now let’s create a replication rule.
 
In S3 Standard storage our data gets replicated in multiple zones, not regions. So anyways our data is replicated.
 
But still, if we want to enable replication for data to be replicated to a different bucket in different regions, then we can do that also.
 
Another reason for setting up such replication rules is that it may be possible that your users are in different regions of the world. So setting up replication for different regions will give you an added advantage.
 
To set this up, go to the bucket management tab and click on create replication rule.
 
 
With the above-mentioned settings, we are replicating the entire objects rather than some specific objects.
 
For now, we have created one more bucket in the same region to hold the replicated data and we named that bucket as bucket-for-replication-08042021, but we can try with buckets in some other regions too.
 
 
Replication requires versioning to be enabled. So we have enabled versioning also.
 
We have also changed the storage type for the destination bucket as we don’t want very frequent access to that data.
 
 
And we can see our replication rule has been set up successfully.
 
 
So, now Let’s add one dummy Image to our existing bucket bucket-07042021 and see if the rule actually works.
 
 
And after some time we can see that this data has been replicated to our newly created bucket as per the replication rule.
 
 

SUMMARY

 
So as we have seen, it's really simple to set up replication and the lifecycle rules for the S3 bucket.
 
Replication actually offers automated and asynchronous copying of objects across different S3 buckets, whether they are in same region or in the different regions. Objects can either be replicated to a single destination bucket or multiple destination buckets. It all depends on your requirements and how you actually want to set up the rules.
 
I hope you find this article helpful. Stay tuned for more … Cheers!!
 
You can also check out some of my previous articles on AWS S3 as mentioned below,


Similar Articles