It is a way of efficiently managing the objects so that the cost is minimized throughout the lifecycle of the lifecycle of the object inside the instance.
It defines a set of rules which help in defining the actions which have to be applied by the S3 bucket instance to the group of objects. The actions can be classified into two types:
- Transition actions: These actions are used to define an object’s transition from one storage class to another. Storage class refers to a storage space that is associated with an object in the Amazon S3 space, and they are highly durable.
There are a wide range of storage classes that are offered by Amazon S3. A storage class can be chosen depending on the requirement. It is chargeable to transition from one storage class to the other.
- Expiration actions: As the name suggests, it defines when an object is about to expire. Amazon S3 takes the responsibility of deleting the object once it expires on the behalf of the user.
Usage of lifecycle configuration
Lifecycle configuration rules can be applied to objects that have a well-defined lifecycle. Well-defined lifecycle examples have been discussed below:
- Frequently accessing certain documents, for a limited time period only. After this, it can be deleted.
- Uploading logs to an S3 bucket, which is needed for a specific time period, post which it can be deleted.
Configuring a lifecycle
A lifecycle configuration is an XML file that consists of a set of rules, which have predefined actions that are used by Amazon S3, to perform actions on an object during its lifetime.
Amazon S3 provides APIs that can be used to manage the lifecycle configuration of an object residing in the S3 bucket. The configuration is stored as a ‘lifecycle subresource’ which is associated with the bucket. The lifecycle can be configured with the help of Amazon S3 console or programmatically with the help of AWS SDK wrapper libraries. REST API calls can be made directly.
Creating a lifecycle rule
Below are the steps to create a lifecycle rule
- Sign into the AWS Management Console.
- Click on the S3 service that you have created previously.
- Create a new bucket in the S3.
- Enter a bucket name for the bucket, and click on ‘Next’ button.
- In the ‘Configure options’ tab, set the versioning, server access logging if you are specific about it. Otherwise it is suggested to leave the default settings.
- Click on the ‘Next’ button.
- Set the permissions or leave the default settings, and click on the ‘Next’ button.
- Click on the ‘Create Bucket’.
- Into this bucket, objects can be uploaded, before which policies can be created for every S3 bucket.
- Go to the ‘Management’ tab, and click on the ‘lifecycle’ tab.
- Provide a lifecycle rule and give an appropriate name to it.
- Click on the ‘Next’ button.
- Check the current version and then click on the ‘Add transition’. A storage class transition can be created in both the current version as well as the previous version.
- Once the object is created, 30 days post this, the object’s storage class gets converted into ‘Standard Infrequently access storage class’. This is considered to be the first transition.
- 60 days post creation of the object, the storage class gets converted into ‘Glacier storage class’.
- Once the object expires, click on ‘Next’ button. This will create a lifecycle rule.
- Click on the ‘Save’ button.
- A lifecycle rule gets created.
In this post, we understood the lifecycle management of Amazon services, along with understanding how to create a lifecycle rule.