Scrutinize S3 Lifecycle Configuration Rules through CloudFormation Import Resources
Tags: aws, cloudformation, s3
Published: 2022-12-04 10:23:26

“ I have checked the documents of AWS to create the s3 lifecycle configuration rules automatically. So I found that it can be possible using cloudformation stack to automate purpose for existing s3 bucket. Pricing of S3 bucket as per storage size.”

An S3 Lifecycle configuration is an XML file that consists of a set of rules with predefined actions that you want Amazon S3 to perform on objects during their lifetime. You can also configure the lifecycle by using the Amazon S3 console, REST API, AWS SDKs and the AWS Command Line Interface (AWS CLI).

Amazon S3 Lifecycle configuration rules run once a day. Check and confirm whether the rule has transitioned the storage class. The total number of objects in the bucket affects the time it takes for you to see the change in storage class.

An S3 Lifecycle configuration can have up to 1,000 rules. This limit is not adjustable. The <ID> element uniquely identifies a rule. ID length is limited to 255 characters.

In this post, you will get to know how to scrutinize s3 lifecycle configuration rules through cloudformation import resources. Here I have created a s3 bucket and s3 lifecycle configuration rules through a cloudformation stack with import resources.

#Prerequisites
You’ll need an Amazon Simple Storage Service for this post. [Getting started with Amazon Simple Storage Service](https://aws.amazon.com/s3/getting-started/) provides instructions on how to create a bucket in simple storage service.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fmzed043vszjizlc122.png)
The architecture diagram shows the overall deployment architecture with data flow, amazon s3 and cloudformation.

#Solution overview
The blog post consist of the following phases:
1. Create of S3 Lifecycle Configuration Rules through CloudFormation
2. Output of Stack as S3 Lifecycle Configuration Rules

I have a s3 bucket as below →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anlkteqa4014w0idzd8q.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxaw0kwodzfxer6j1f2m.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8kslmafugsf4notb3ts.png)

##Phase 1: Create of S3 Lifecycle Configuration Rules through CloudFormation
1. Open the cloudformation console and create a stack to import resources as an existing bucket with identifier property and its identifier value. Also the template .yaml file is customized with required parameters for s3 lifecycle rules.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/110lfpnw3cgo0r31hsla.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v05nfytanni2d2wqg07k.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmvhd1i19p0pseaoxrpm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymxfwvwh7dp11km8fqji.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk2ojo5rlz2thv3n2z1h.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7dj7etzaazivuidc8pyu.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/acq2x0ylhudaqshpwvhl.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ggyy89t3lzhuv0nqgqd.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zbglhrl8h5cte89mrt7n.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxw9liw9knbafs649owf.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zociltg8c6qtnzvspsg4.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0zbmqv874l0i1vhgxlo.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zoacehe5dp5qmm3vllv5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/woudzr9j7ahk56v2pzwg.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3l2n5wwj8vwq6fc6txst.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7e9h2nat5mrmfevp2n4b.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3kj5revez3i3tsyfc29.png)

##Phase 2: Output of Stack as S3 Lifecycle Configuration Rules
1. Open the s3 bucket console and check the created lifecycle configuration rules.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nib0hpcwcbdqmgxwhof9.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zj8qyqvmi9gtjatqz8uj.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5drj9xqj4wqlhbl9v60v.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nlwl6vcmx6ikrb6u8v7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxbrwecvbity5r66n1o9.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6k4ccs68hu4cshk3y19j.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hiu17lgfwi7xoeim8so7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5beh3nkk4widolqdu1l.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ujnkwoh74o2q9ap2v0n.png)

#Clean-up
Delete S3 Bucket and Cloudformation Stack.

#Pricing
I review the pricing and estimated cost of this example. 

Cost of Data Transfer = $0.0

Cost of S3 = $0.009

Total Cost = $0.009

#Summary
In this post, I showed “scrutinize s3 lifecycle configuration rules through cloudformation import resources”.

For more details on Amazon S3, Checkout Get started Amazon S3, open the [Amazon S3 console](https://s3.console.aws.amazon.com/s3/get-started?region=us-east-1). To learn more, read the [Amazon S3 documentation](https://docs.aws.amazon.com/s3/?icmpid=docs_homepage_featuredsvcs).

For more details on AWS CloudFormation, Checkout Get started AWS CloudFormation, open the [AWS CloudFormation console](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/). To learn more, read the [AWS CloudFormation documentation](https://docs.aws.amazon.com/cloudformation/?id=docs_gateway).

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)