How to create a lifecycle policy for an S3 Bucket on AWS

We can use the Lifecycle Policy to manage the objects in S3 Bucket so that they are stored cost-effectively throughout. An S3 Lifecycle Policy is a set of rules used to define actions that Amazon S3 applies to objects in the bucket. There are two types of actions:

  1. Transition actions: 
     This is used to define when objects transition to another storage class.  
  2. Expiration actions:
    This is used to define when objects expire. 

We can add rules in the policy to tell Amazon S3 to transition objects to another Amazon S3 storage class.

For Example: 

  1. When we know that objects are infrequently accessed, we might transition them to the S3 Standard-IA storage class.
  2. We might want to archive objects that we don't need to access in real-time to the S3 Glacier storage class.

To know more about the transition in detail, click here to visit the official documentation.

We can use the S3 Lifecycle Policy in the following cases.

  1. When we want to upload logs to a bucket needed for a week or a month and after that, we might want to delete them.
  2. When documents are frequently accessed for a limited period of time.
  3. When we want to upload some types of data to Amazon S3 primarily for archival purposes.

We can add S3 Lifecycle configurations to unversioned buckets and versioning-enabled buckets.

In this article, we will see the steps to move objects (Transition Action) to Glacier after 10 days of creation and delete(Expirations Action) them after 365 days of creation.

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. Create a Lifecycle Policy

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 login using our login details.

Login-Page

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

AWS-Management-Console

Create a Lifecycle Policy

Click on "Services" in the top left of the screen and then search for s3 in the search box.

Search-S3-Service

You will see the main dashboard of the S3 where you will see all the S3 buckets from your account. Click on your S3 bucket in which you want to create a lifecycle policy. If you do not have an S3 bucket and want to learn to create your first bucket then click here.

Note: While creating an S3 Bucket make sure that the name you give to the Bucket is unique globally as no 2 buckets can have the same name. You can not have buckets with the same name not only in your account but throughout the globe.

S3-Main-Dashboard

Inside the S3 Bucket, click in the Management tab.

S3-Bucket

You will see a screen as follows, specify a name for the policy to be created and choose the scope as "Apply to all objects in the bucket" if you want to apply this policy on all the objects in the bucket.

Rule-Name-Screen

Choose the object version on which you want to apply the lifecycle/transition policy. Here I have chosen the current version.

Here I have chosen the transition to Glacier and specified 10 days as the number of days after the creation of the object that I want the transition to be applied.

Click on the acknowledgment checkbox and then on Next.

Storage-Class-Transition-Screen

Here I have chosen the current version of the object for expiration and specified 365 days as the number of days after object creation to delete the object.

If you want to try to create a policy for the previous version of documents as well, check on the "Previous versions" checkbox.

Click on the Next Button.

Configure-Expiration-Screen

Verify the settings for the rule we created if you need to make changes, choose Previous. Otherwise, click on the acknowledgment checkbox and then on the Save button.

Review-Policy

Here, you can see the rule we created that will move the current version of the objects to Glacier after 10 days of creation and will delete the current version of the objects after 365 days of creation.

Lifecycle-Policy

Conclusion

In this article, we saw the step to create a lifecycle policy on s3 buckets to move the current version of the objects to Glacier and delete the current version of the objects from the bucket.

Share this page:

Suggested articles

0 Comment(s)

Add comment