Ch. 15 · AWS

AWS S3 Lifecycle Policies

Move objects to cheaper storage classes and expire them automatically with S3 lifecycle rules.

~2 min readintermediateupdated Oct 5, 2026

Storing every object in the standard class forever is expensive. A lifecycle policy moves objects to cheaper classes as they age and deletes them when they are no longer needed, so retention and cost are managed by rule instead of manual cleanup.

Before you start

You should be comfortable with S3 buckets and prefixes. This article covers lifecycle transitions and expiration.

Step-by-step walkthrough

Step 1: Define rules by prefix or tag

A lifecycle rule filters objects by prefix or tag and applies transitions and expiration. Scoping by prefix, such as logs/, keeps the rule predictable. A rule without a filter applies to the whole bucket, which may be broader than intended.

Step 2: Transition to colder classes

Objects move from standard to infrequent access and then to archival classes on a schedule, each cheaper to store but slower to retrieve and with a minimum storage duration. Match the transitions to how often the data is accessed, since early transition to an archival class can cost more if the data is still read.

Step 3: Expire or delete deliberately

Expiration removes objects after a set age, and noncurrent version expiration cleans up old versions in a versioned bucket. Without version expiration, versions accumulate and consume the storage the deletion was meant to free.

Worked scenario

The rule ages logs through classes and deletes them.

{
  "Rules": [{
    "ID": "logs-lifecycle",
    "Filter": { "Prefix": "logs/" },
    "Status": "Enabled",
    "Transitions": [
      { "Days": 30, "StorageClass": "STANDARD_IA" },
      { "Days": 90, "StorageClass": "GLACIER" }
    ],
    "Expiration": { "Days": 365 },
    "NoncurrentVersionExpiration": { "NoncurrentDays": 30 }
  }]
}
JSON

Walk through the example

Logs move to infrequent access after thirty days, to Glacier after ninety, and are deleted after a year. Old versions are removed thirty days after they become noncurrent, so a versioned bucket does not grow forever. The prefix keeps the rule scoped to logs.

Common mistake

No lifecycle policy at all, so logs and old versions accumulate indefinitely. Another is transitioning to an archival class too early for data that is still read, which incurs retrieval costs that exceed the storage saving.

Verify the behavior

List objects and confirm transitions occur by age. Check that expired objects disappear after the configured days. In a versioned bucket, confirm noncurrent versions are removed so storage actually shrinks.

Interview exercise

Why is noncurrent version expiration important in a versioned bucket?

Answer and reasoning

Because versioning keeps every prior version, so deleting an object only adds a delete marker and the old versions still occupy storage. Without expiration, the bucket grows even as objects are “deleted”. Noncurrent version expiration removes the superseded versions, which is what actually frees space and cost.

Continue learning

Compare storage durability in S3 versioning and consistency in S3 consistency and access. Read the AWS S3 lifecycle documentation and try the AWS interview questions.

More in AWS

read ✓AWS · mid

AWS S3 Versioning and Recovery Limits

AWS S3 Versioning and Recovery Limits. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readread →
esc