S3 lifecycle policy generator
Choose when objects move to cheaper storage and when they are deleted. You get the lifecycle JSON for the AWS CLI and the Terraform, with warnings for the 30-day, 128 KB and minimum-duration traps.
Runs in your browser, nothing is uploadedLifecycle JSON for the AWS CLI
Save it as lifecycle.json, then run:
Terraform
Applying a lifecycle configuration replaces any rules the bucket already has. Read the current ones first with aws s3api get-bucket-lifecycle-configuration and merge them.
How to use the S3 lifecycle policy generator
- Name the rule and set the prefix the rule should cover, such as logs/. Leave it empty to cover the whole bucket.
- Tick the storage classes objects should move to and the day each move happens, then set when objects and old versions are deleted.
- Read the warnings, then copy the JSON for the AWS CLI or the Terraform. Applying it replaces the bucket's existing rules, so merge them first.
Example: application logs kept for a year
Logs under logs/ move to Standard-IA after 30 days, to Glacier Instant Retrieval after 90, and are deleted after 365. A cleanup rule removes old versions after 30 days and incomplete uploads after 7.
For 1 TB of logs, that cuts storage from about $23.50 a month in Standard to around $4 for the older data, and stops the bucket growing forever.
Common questions
Why can objects not move to Standard-IA before 30 days?
S3 only allows lifecycle transitions to Standard-IA for objects at least 30 days old, and bills Standard-IA for at least 30 days.
Should I use Intelligent-Tiering instead?
Use Intelligent-Tiering when you cannot predict access, such as user uploads. Use lifecycle rules for data with a known life, such as logs and backups.
Why add a separate cleanup rule?
Incomplete multipart uploads and old versions are billed but easy to forget. A rule with no filter covers the whole bucket.
Read next: S3 Intelligent-Tiering vs lifecycle rules: which one saves more
Want the real numbers for your AWS account?
Send me your setup and I will return a written list of savings and security fixes, safest first. It is free.