Automate S3 Storage class lifecycle using Terraform

jaffar shaik
2 min readOct 6, 2022

S3 Storage Classes can be configured at the object level and a single bucket can contain objects stored across S3 Standard, S3 Intelligent-Tiering, S3 Standard-IA, and S3 One Zone-IA. we can use S3 Lifecycle policies to automatically transition objects between storage classes without any application changes.

To apply lifecycle rule we need to create a bucket.

step 1: Creating a bucket

Figure : Bucket Creation

step 2:

when we enabled s3 lifecycle then only object will move from one storage class to another.

if s3 lifecycle transition not required or disabled we can disable it .In that case object will present only in initial storage class and it won't move further.

Figure: Enabling s3 lifecycle

step 3:

sometimes Logs are required for an existing bucket means if we set variable Logging = TRUE. this will enable the logs for the bucket. this will create the following resource.

Figure : Enabling logs for bucket

Note :

if Logs are not enabled Logging = FALSE for the bucket the above resource will not created. In this case we can't find logs for the bucket.

The source code is available in below repository

Jaffarterraform786/s3-lifecycle-enable (github.com)

The following resources will be created.

Figure s3-life cycle and s3 module resources.

--

--