Reading25 min read·Module 4High exam weight

S3 Lifecycle Policies

Key concepts

  • Transition actions

  • Expiration actions

  • Filter by prefix/tags

  • Multipart upload cleanup

  • Versioning considerations

Overview

Amazon S3 Lifecycle policies enable automated management of objects throughout their lifecycle, transitioning data to lower-cost storage classes and automatically expiring objects based on defined rules. This is a critical topic for the SAA-C03 exam.

Core Concept

S3 Lifecycle configurations consist of rules that define transition actions (move to cheaper storage classes) and expiration actions (delete objects). Rules can be applied to all objects, by prefix, or by object tags. Lifecycle rules run once per day asynchronously.

Exam Tip

Lifecycle policies can 'transition' or 'expire' objects, but NOT 'protect' them. For protection from deletion, use S3 Object Lock. This distinction appears frequently in exam questions.

Key Concepts

Lifecycle Action Types

S3 Lifecycle Transition and Expiration Actions
Figure 1: S3 Lifecycle Action Types Overview

Transition Actions

Purpose: Automatically move objects to lower-cost storage classes based on age

How It Works:

  • Define number of days after object creation
  • Objects transition to specified storage class
  • Can chain multiple transitions (Standard → IA → Glacier)

Supported Transitions:

S3 Standard → Any lower tier
S3 Standard-IA → One Zone-IA, Glacier tiers
S3 Intelligent-Tiering → Glacier tiers only
S3 One Zone-IA → Glacier Flexible/Deep Archive only

Constraints:

  • Minimum 30 days before transition to IA classes
  • Cannot transition to S3 Standard or Express One Zone
  • Objects < 128 KB not recommended for IA transitions

Expiration Actions

Purpose: Automatically delete objects after a specified period

How It Works:

  • Define number of days or specific date for expiration
  • S3 deletes objects on your behalf (asynchronously)
  • Commonly used for log files, temporary data

Behavior by Bucket State: | Bucket Versioning | Expiration Behavior | |-------------------|---------------------| | Disabled | Object permanently deleted | | Enabled | Delete marker added (object becomes noncurrent) | | Suspended | Delete marker added with null version ID |

Use Cases:

  • Regulatory compliance (delete after retention period)
  • Log file cleanup
  • Temporary data management

Multipart Upload Cleanup

Purpose: Abort and clean up incomplete multipart uploads

The Problem:

  • Incomplete multipart uploads consume storage and incur charges
  • Uploads not visible in normal bucket listings
  • Can accumulate over time, wasting money

Configuration:

{
  "AbortIncompleteMultipartUpload": {
    "DaysAfterInitiation": 7
  }
}

Key Limitation: Cannot use object tag filters with this action

Best Practice: Apply to all buckets with multipart upload activity (typically 7 days is a safe default)

Versioning Considerations

Lifecycle Behavior with Versioned Objects
Figure 2: Lifecycle Actions on Versioned Objects

Noncurrent Version Management

Purpose: Manage previous versions of objects in versioned buckets

Available Actions:

  1. NoncurrentVersionTransition

    • Transition noncurrent versions to cheaper storage
    • Configure days since object became noncurrent
    • Optionally specify number of versions to retain (1-100)
  2. NoncurrentVersionExpiration

    • Permanently delete noncurrent versions
    • Based on days since becoming noncurrent
    • Can specify maximum versions to retain

Example Configuration:

{
  "NoncurrentVersionTransition": {
    "NoncurrentDays": 30,
    "StorageClass": "GLACIER",
    "NewerNoncurrentVersions": 3
  },
  "NoncurrentVersionExpiration": {
    "NoncurrentDays": 365,
    "NewerNoncurrentVersions": 1
  }
}

Expired Object Delete Markers

Purpose: Clean up delete markers that no longer have associated versions

What Is It?

  • A delete marker with zero noncurrent versions
  • Created when all previous versions are deleted/expired
  • Does NOT incur storage charges
  • CAN impact LIST operation performance

Cleanup Action:

{
  "Expiration": {
    "ExpiredObjectDeleteMarker": true
  }
}

When to Use: Buckets with high churn where objects are frequently deleted and expire

Lifecycle Rule Configuration

JSONComplete Lifecycle Configuration Example
{
  "Rules": [
    {
      "ID": "LogFileManagement",
      "Status": "Enabled",
      "Filter": {
        "Prefix": "logs/"
      },
      "Transitions": [
        {
          "Days": 30,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 90,
          "StorageClass": "GLACIER"
        }
      ],
      "Expiration": {
        "Days": 365
      }
    },
    {
      "ID": "CleanupMultipartUploads",
      "Status": "Enabled",
      "Filter": {
        "Prefix": ""
      },
      "AbortIncompleteMultipartUpload": {
        "DaysAfterInitiation": 7
      }
    },
    {
      "ID": "VersionManagement",
      "Status": "Enabled",
      "Filter": {
        "Prefix": "documents/"
      },
      "NoncurrentVersionTransitions": [
        {
          "NoncurrentDays": 30,
          "StorageClass": "STANDARD_IA"
        }
      ],
      "NoncurrentVersionExpiration": {
        "NoncurrentDays": 90,
        "NewerNoncurrentVersions": 5
      }
    }
  ]
}
SHAWS CLI - Lifecycle Configuration Commands
# View current lifecycle configuration
aws s3api get-bucket-lifecycle-configuration \
  --bucket my-bucket

# Apply lifecycle configuration from file
aws s3api put-bucket-lifecycle-configuration \
  --bucket my-bucket \
  --lifecycle-configuration file://lifecycle.json

# Delete lifecycle configuration
aws s3api delete-bucket-lifecycle \
  --bucket my-bucket

# List incomplete multipart uploads (to verify cleanup)
aws s3api list-multipart-uploads \
  --bucket my-bucket

Transition Constraints

S3 Storage Class Transition Waterfall
Figure 3: Valid Storage Class Transitions

Minimum Days Between Transitions

From Storage ClassTo Storage ClassMinimum Days
S3 StandardS3 Standard-IA30
S3 StandardS3 One Zone-IA30
S3 StandardS3 Intelligent-Tiering0
S3 StandardS3 Glacier Instant0
S3 StandardS3 Glacier Flexible0
S3 StandardS3 Glacier Deep Archive0
S3 Standard-IAS3 One Zone-IA30
S3 Standard-IAS3 Glacier (any)0
S3 Intelligent-TieringS3 Glacier Flexible0
S3 Intelligent-TieringS3 Glacier Deep Archive0

Best Practices

  1. Analyze Access Patterns First: Use S3 Storage Class Analysis for at least 30 days before defining transition rules
  2. Start Simple, Then Scale: Begin with basic rules and add complexity as you understand your data patterns
  3. Test in Non-Production: Validate lifecycle rules on test data before applying to production buckets
  4. Document Your Policies: Maintain documentation explaining the business rationale for each rule
  5. Clean Up Incomplete Uploads: Always include an AbortIncompleteMultipartUpload rule (7 days recommended)
  6. Manage Versions Proactively: Use NoncurrentVersionExpiration to prevent version accumulation
  7. Review Regularly: Access patterns change; review and update policies quarterly

Common Exam Scenarios

Exam Scenario Decision Guide

ScenarioRecommended ConfigurationKey Reasoning
Log files accessed frequently for 30 days, rarely afterTransition to Standard-IA at 30 days, Glacier at 90 days, expire at 365 daysMatches access pattern with cost optimization
Compliance data must be retained 7 years, never accessedTransition to Glacier Deep Archive immediately, expire at 2555 daysLowest cost for long-term retention
Backup files with unpredictable accessTransition to Intelligent-Tiering immediatelyAutomatic tier management without retrieval fees
Temporary uploads that may failAbortIncompleteMultipartUpload after 7 daysPrevents orphaned upload parts from accumulating
Versioned documents with 5 versions neededNoncurrentVersionExpiration with NewerNoncurrentVersions: 5Retains required versions, cleans up older ones
Application generates many small filesKeep in S3 Standard or Intelligent-TieringSmall object overhead makes IA classes inefficient
Compliance requires 30-day recovery window then archiveTransition current to Glacier at 30 days, noncurrent versions expire at 30 daysBalances recovery needs with cost
High-churn bucket with many deletionsExpiredObjectDeleteMarker: trueImproves LIST performance by cleaning markers

Common Pitfalls

Minimum Storage Duration Charges

Transitioning or deleting objects before their minimum storage duration (30 days for IA, 90 days for Glacier Instant/Flexible, 180 days for Deep Archive) incurs pro-rated charges. Lifecycle rules don't prevent these charges—they still apply.

Cannot Override with Bucket Policy

Bucket policies CANNOT prevent lifecycle rule deletions or transitions. Even with an explicit deny for all principals, lifecycle rules execute normally. Use S3 Object Lock for immutable data protection.

Small Object Inefficiency

Objects smaller than 128 KB are charged as 128 KB in IA and Glacier Instant classes. Additionally, minimum storage duration applies. For many small files, the lifecycle transition may cost more than keeping objects in Standard.

Lifecycle Rules Run Daily

S3 runs lifecycle rules once per day (not continuously). There can be up to a 24-48 hour delay between when an object becomes eligible and when the action occurs. Don't rely on immediate transitions.

Multipart Cleanup Tag Limitation

The AbortIncompleteMultipartUpload action CANNOT use object tag filters—only prefix filters or apply to entire bucket. Plan your bucket structure accordingly if you need selective multipart cleanup.

Quick Reference

Lifecycle Configuration Limits

LimitValue
Maximum rules per bucket1,000
Maximum prefix length1,024 characters
Minimum transition to IA classes30 days
Rule evaluation frequencyOnce per day
Maximum versions to retain100

Key CLI Commands

# Get lifecycle configuration
aws s3api get-bucket-lifecycle-configuration --bucket BUCKET_NAME

# Put lifecycle configuration
aws s3api put-bucket-lifecycle-configuration \
  --bucket BUCKET_NAME \
  --lifecycle-configuration file://lifecycle.json

# Delete lifecycle configuration
aws s3api delete-bucket-lifecycle --bucket BUCKET_NAME

# List incomplete multipart uploads
aws s3api list-multipart-uploads --bucket BUCKET_NAME

# Abort specific multipart upload
aws s3api abort-multipart-upload \
  --bucket BUCKET_NAME \
  --key OBJECT_KEY \
  --upload-id UPLOAD_ID

Filter Types

Filter TypeUse CaseExample
PrefixPath-based rules"Prefix": "logs/"
TagContent-based rules"Tag": {"Key": "archive", "Value": "true"}
Combined (AND)Specific subsetsPrefix AND Tag combined
Object SizeSize-based rules"ObjectSizeGreaterThan": 131072

Test Your Knowledge

Q

A company stores application logs in S3. Logs are accessed frequently for 7 days, occasionally for 30 days, and must be retained for 1 year for compliance. Which lifecycle configuration minimizes costs while meeting requirements?

ATransition to Standard-IA at 7 days, Glacier at 30 days, expire at 365 days
BTransition to Standard-IA at 30 days, Glacier at 60 days, expire at 365 days
CTransition to Glacier immediately, expire at 365 days
DUse Intelligent-Tiering with Archive Access tier enabled
Q

A versioned S3 bucket accumulates many noncurrent object versions, increasing costs. The company wants to keep only the 3 most recent noncurrent versions and delete older ones after 90 days. Which lifecycle action achieves this?

ANoncurrentVersionExpiration with NoncurrentDays: 90
BNoncurrentVersionExpiration with NoncurrentDays: 90 and NewerNoncurrentVersions: 3
CExpiration with Days: 90
DNoncurrentVersionTransition with NoncurrentDays: 90
Q

An S3 bucket receives many multipart uploads from an application. Some uploads fail and leave incomplete parts. The operations team notices storage costs are higher than expected. What is the MOST cost-effective solution?

AManually delete incomplete uploads weekly
BAdd lifecycle rule: AbortIncompleteMultipartUpload with DaysAfterInitiation: 7
CDisable multipart upload capability
DTransition incomplete uploads to Glacier
Q

A company has a lifecycle rule that transitions objects to S3 Glacier Flexible Retrieval after 30 days. They delete an object on day 25. What charges apply?

ANo charges since the object was deleted before transition
BOnly the 25 days of S3 Standard storage
C25 days of S3 Standard storage plus 5 days of pro-rated Standard charges
D25 days of S3 Standard storage plus 90 days of Glacier charges

Further Reading

Related services

S3