🛠 Step-by-Step Guide

  1. Create an S3 Bucket bash Copy Edit aws s3api create-bucket --bucket my-lifecycle-bucket-001 --region us-east-1
  2. Upload Some Test Files bash Copy Edit echo "example data" > file.txt aws s3 cp file.txt s3://my-lifecycle-bucket-001/data/
  3. Define the Lifecycle Configuration Create a file called lifecycle-policy.json with the following content:

json
Copy
Edit
{
"Rules": [
{
"ID": "ArchiveAndDeletePolicy",
"Filter": {
"Prefix": "data/"
},
"Status": "Enabled",
"Transitions": [
{
"Days": 30,
"StorageClass": "STANDARD_IA"
},
{
"Days": 60,
"StorageClass": "GLACIER"
}
],
"Expiration": {
"Days": 90
}
}
]
}
📝 Note: The Prefix value targets files under the data/ folder.

  1. Apply the Lifecycle Policy bash Copy Edit aws s3api put-bucket-lifecycle-configuration \ --bucket my-lifecycle-bucket-001 \ --lifecycle-configuration file://lifecycle-policy.json
  2. Verify the Configuration bash Copy Edit aws s3api get-bucket-lifecycle-configuration --bucket my-lifecycle-bucket-001 ✅ Results Objects in data/ move to cheaper storage automatically.

After 90 days, they’re deleted — no manual cleanup needed.

You reduce costs and enforce data retention policies easily.