Day 17: AWS - S3

satyam mishrasatyam mishra
2 min read

Lifecycle Rules – Teaching My S3 Bucket to Clean Up After Itself

Let’s be honest — my S3 buckets were starting to feel like my Downloads folder.
Messy. Untouched. Full of old junk I swore I’d "clean up later".

So I explored S3 Lifecycle Rules — and wow, it’s like setting up automated house cleaning for your storage.


What Are Lifecycle Rules?

They’re basically:

“If this file gets old, do something about it.”

AWS lets you automate:

  • Transitioning files to cheaper storage (like Glacier)

  • Deleting files after a set time

  • Expiring versions in versioned buckets

I liked the idea of:

  • Moving old logs to Glacier after 30 days

  • Deleting old temp files after 60 days


My First Lifecycle Rule (from the AWS Console)

Here’s what I did:

  1. Went to my S3 bucket (my-archive-demo)

  2. Clicked Management → Lifecycle rules → Create rule

  3. Named it: auto-glacier-30days

  4. Set filter: apply to all objects

  5. Rule action:

    • Transition to Glacier Instant Retrieval after 30 days

    • Delete after 180 days (just to test it)

Saved it — and that was it.


Tried With Versioning Too

I enabled versioning on a test bucket.
Then added a second rule to:

  • Expire non-current versions after 7 days

S3 doesn’t delete current files — just the older versions you no longer need.


Why This Matters

  • Cheaper storage → S3 Glacier is way cheaper than Standard

  • Cleaner buckets → no more forgotten test files from 10 days ago

  • Set-it-and-forget-it → AWS does the cleanup without needing Lambda or scripts


Bonus: Lifecycle Rule via CLI

Just for the thrill, I checked the JSON of my rule. Here’s a simple version:

{
  "Rules": [
    {
      "ID": "log-archiving",
      "Prefix": "",
      "Status": "Enabled",
      "Transitions": [
        {
          "Days": 30,
          "StorageClass": "GLACIER_IR"
        }
      ],
      "Expiration": {
        "Days": 180
      }
    }
  ]
}

You can apply this with put-bucket-lifecycle-configuration via AWS CLI or SDK.


Today I Learned

  • Lifecycle rules are low effort, high value.

  • You can apply them to all objects, or use filters like prefixes/tags.

  • They're ideal for logs, temp uploads, backups, and versioned data.

  • No Lambda. No cron. Just... set the rule and forget it.

0
Subscribe to my newsletter

Read articles from satyam mishra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

satyam mishra
satyam mishra