What are S3 lifecycle rules and what can they do?
Lifecycle rules automatically move objects to cheaper storage classes after a set number of days, or delete them. They also clean up old versions and incomplete multipart uploads.
Explain it simply
Think of clearing your wardrobe. Clothes worn this month stay in the cupboard (Standard). After a few months they go to the loft (Infrequent Access), and after a year to a trunk in the store room (Glacier). After five years you donate them (expiration). A lifecycle rule is that routine written down, applied automatically.
Example
{
"Rules": [{
"ID": "logs-tiering",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" },
{ "Days": 90, "StorageClass": "GLACIER" }
],
"Expiration": { "Days": 365 },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
}]
}Two kinds of actions exist: transition (change storage class) and expiration (delete). Rules can target a prefix, a tag, or the whole bucket, and can handle noncurrent versions separately.
Transitions must follow the allowed order, generally moving down toward colder classes, and Standard to Standard-IA needs the object to be at least 30 days old. Very small objects may not be worth moving because of minimum billable size charges.
What to say in the interview
"Lifecycle rules automate transitions to colder storage classes and expiration of data, scoped by prefix or tag. I use them for logs and backups, and always add a rule to abort incomplete multipart uploads and to expire old noncurrent versions."
Common mistakes
- Transitioning millions of tiny objects, where request and minimum-size charges outweigh savings.