Data cools as it ages: this week's logs are read daily, last year's almost never. A lifecycle rule moves objects to colder classes as they age, and deletes them at the end.
STANDARDday 0
day 30
STANDARD_IAcheaper to keep
day 90
GLACIERmust be restored to read
day 365
deletedexpired
The rule
json
{
"Rules": [{
"ID": "logs-age",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" },
{ "Days": 90, "StorageClass": "GLACIER" }
],
"Expiration": { "Days": 365 },
"NoncurrentVersionExpiration": { "NoncurrentDays": 30 }
}]
}Filterlimits the rule to a prefix;{ "Prefix": "" }is the whole bucket.Transitionsmove the object when it reaches each age.Expirationdeletes the current version at that age.NoncurrentVersionExpirationdeletes old versions a number of days after they stop being the latest, which keeps a versioned bucket's bill in check.
Applying it
sh
aws s3api put-bucket-lifecycle-configuration --bucket market-docs-w8rjis --lifecycle-configuration file://lifecycle.jsonsh
aws s3api get-bucket-lifecycle-configuration --bucket market-docs-w8rjisThe put replaces every rule on the bucket, so one file holds them all. From then on S3 applies the rules once a day, with nothing for you to run.