AWS › S3 & Storage

How do S3 lifecycle policies automatically transition objects between storage classes or delete them entirely based on defined rules?

Intermediate

Answer

S3 lifecycle policies let you define rules that automatically transition objects to a different, typically cheaper, storage class after a specified number of days, or automatically delete objects entirely after they are no longer needed, removing the need to manually manage the ongoing storage class and retention of potentially millions of individual objects yourself.
aws s3api put-bucket-lifecycle-configuration --bucket my-bucket --lifecycle-configuration file://lifecycle-policy.json
Real-world example A company configures a lifecycle policy that automatically moves log files older than thirty days into S3 Infrequent Access, then into Glacier after ninety days, and finally deletes them entirely after seven years to meet their data retention policy, all without any manual intervention.

Common follow-ups: How quickly do lifecycle policy transitions actually take effect after an object reaches the defined age threshold?;Can lifecycle policies apply to only a specific subset of objects within a bucket based on a prefix or tag?