Sub topic 8
Storage tiering and lifecycle policies
This chapter assumes you know what an S3 bucket and object are, can run the AWS CLI, and can read JSON. It also assumes you have seen the storage line items in your bill from earlier chapters. Here you will learn how storage classes trade price for access, how lifecycle rules move or delete data on a schedule, and which edge cases turn a saving into a surprise charge.
Why storage costs grow quietly
Storage is billed per GB per month, so data you never delete keeps costing money. Logs, backups, build artifacts and old object versions accumulate, and nobody notices because each day's increase is small. Most of that data is rarely read after the first few weeks.
Tiering means keeping data in a class whose price matches how often you read it. A lifecycle policy applies that decision automatically, so you don't depend on someone remembering to clean up.
The trade-off behind storage classes
Cheaper storage classes charge less per GB stored but add costs elsewhere. Those costs are retrieval fees, minimum storage durations, minimum object sizes, slower access, or monitoring fees. A class is a good choice only when the extra costs stay small for your access pattern.
| Class | Best for | Minimum duration | Retrieval cost and speed |
|---|---|---|---|
| Standard | Frequently read data | None | No retrieval fee, milliseconds |
| Intelligent-Tiering | Unknown or changing patterns | None | No retrieval fee, per-object monitoring fee |
| Standard-IA | Infrequent reads, needs fast access | 30 days | Per-GB retrieval fee, milliseconds |
| Glacier Instant Retrieval | Rare reads, needs fast access | 90 days | Per-GB retrieval fee, milliseconds |
| Glacier Flexible Retrieval | Archives, read a few times a year | 90 days | Retrieval fee, minutes to hours |
| Glacier Deep Archive | Long-term compliance copies | 180 days | Retrieval fee, hours |
Check the current S3 pricing page for your Region before you decide. Minimums, object-size rules and rates change over time.
Standard-IA versus Intelligent-Tiering
Standard-IA suits data whose access pattern you know. Logs older than 30 days that are read only during incidents are a typical case. You pay a retrieval fee each time you read, so it loses its advantage if the data turns out to be read often.
Intelligent-Tiering moves each object between access tiers based on observed use, and you pay no retrieval fee. The cost is a small monitoring and automation charge per object. That charge can outweigh the saving for very many small objects, and objects under 128 KB are not monitored or auto-tiered. Use it when you can't predict access, and use lifecycle rules to Standard-IA or Glacier when you can.
How lifecycle rules work
A lifecycle configuration is a list of rules attached to a bucket. Each rule has:
- A filter that selects objects by prefix, tag, object size, or any combination. An empty filter selects everything.
- A status, either
EnabledorDisabled. - One or more actions: transition to another class, expire (delete) objects, handle noncurrent versions, or abort incomplete multipart uploads.
Days are counted from the object's creation date. S3 evaluates rules asynchronously, roughly once a day, so a change doesn't take effect instantly. Billing for the new class starts when the transition happens.
A first lifecycle policy
This policy moves objects under logs/ to Standard-IA after 30 days and deletes them after 365 days.
aws s3api put-bucket-lifecycle-configuration \
--bucket my-example-bucket \
--lifecycle-configuration file://lifecycle.json{
"Rules": [
{
"ID": "logs-tiering",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" }
],
"Expiration": { "Days": 365 }
}
]
}Replace my-example-bucket with your bucket name. Then read the configuration back to confirm what S3 stored:
aws s3api get-bucket-lifecycle-configuration --bucket my-example-bucketEstimating whether a transition pays off
Take a bucket with 50,000 GB of logs spread over 10 million objects, averaging 5 MB each. Assume these illustrative rates: Standard at 0.023 USD per GB-month, Standard-IA at 0.0125 USD per GB-month, and 0.01 USD per 1,000 transition requests.
- Standard cost: 50,000 × 0.023 = 1,150 USD per month.
- Standard-IA cost: 50,000 × 0.0125 = 625 USD per month.
- Monthly saving: 525 USD.
- One-time transition cost: 10,000 thousand-request units × 0.01 = 100 USD.
The transition pays for itself in about six days of savings. Now change the object size to 50 KB with the same total volume. That is 1 billion objects, and the transition cost becomes 10,000 USD, which takes about 19 months to recover. Small objects are the most common reason a lifecycle rule loses money.
To handle this, add a size condition so that only larger objects transition. A filter with several conditions uses And:
{
"ID": "logs-large-only",
"Status": "Enabled",
"Filter": {
"And": {
"Prefix": "logs/",
"ObjectSizeGreaterThan": 131072
}
},
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" }
]
}The value is in bytes, so 131072 is 128 KB. For many small files, consider combining them into larger archives (for example, daily compressed bundles) before they reach S3.
Rules that save money without changing tiers
Some of the biggest wins come from deleting data you can't see in a normal object listing.
Incomplete multipart uploads
A failed large upload can leave parts that are stored and billed but don't appear as objects. This rule removes them after 7 days for the whole bucket:
{
"ID": "abort-incomplete-uploads",
"Status": "Enabled",
"Filter": {},
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
}Noncurrent versions
With versioning enabled, overwriting or deleting an object keeps the old version, and you keep paying for it. This rule permanently deletes noncurrent versions 30 days after they become noncurrent, while always keeping the three most recent ones:
{
"ID": "trim-old-versions",
"Status": "Enabled",
"Filter": { "Prefix": "backups/" },
"NoncurrentVersionExpiration": {
"NoncurrentDays": 30,
"NewerNoncurrentVersions": 3
}
}Put the three rules from this section and the earlier ones into one Rules array in a single file, then apply it once. Rules with overlapping filters can conflict, so keep each prefix handled by one rule where you can.
Common errors and gotchas
- Transition order. Transitions only move down the hierarchy, such as Standard to Standard-IA to Glacier. You can't use a lifecycle rule to move data back to Standard. Restoring from Glacier is a separate request that creates a temporary copy.
- Minimum days. Standard to Standard-IA needs at least 30 days. Transitioning to Glacier after 20 days and then to Deep Archive after 40 days also breaks the minimum-duration logic and generates early-deletion charges.
- Expiration is permanent. In an unversioned bucket, expired objects are gone. Test a new expiration rule on a narrow prefix, or with a tag filter, before widening it.
- Retrieval surprises. An analytics job that scans a Glacier-class prefix can cost more in retrieval fees than months of storage savings. Check who reads the data before you archive it.
- Other storage types. EBS snapshots, EFS and DynamoDB have their own mechanisms, such as Data Lifecycle Manager for snapshots, EFS Infrequent Access lifecycle management, and the DynamoDB Standard-IA table class. The same questions apply: how often is the data read, and what does it cost to read it?
Checklist
- Group data by access pattern and owner, using prefixes or tags.
- Check object sizes and counts per prefix.
- Pick a class using the minimum duration and retrieval cost, not only the storage price.
- Add cleanup rules for multipart uploads and noncurrent versions.
- Read back the configuration and monitor the storage and request lines in Cost Explorer over the next billing cycle.
Exercise
A bucket holds 200 million objects of about 20 KB each. A teammate proposes a lifecycle rule that moves everything to Standard-IA after 30 days to cut the storage price. Give two reasons the rule might raise your bill, and name one change that would make it safer.
Show answer
First, transition requests are charged per 1,000 objects, so moving 200 million objects costs a large one-time amount (at the illustrative 0.01 USD per 1,000 rate, 2,000 USD) against a small per-GB saving, because the total volume is only about 4,000 GB. Second, small objects are billed at a minimum size of 128 KB in Standard-IA, so each 20 KB object is charged as 128 KB, which can cost more than Standard. A safer change is to add an ObjectSizeGreaterThan filter of 131072 bytes so small objects stay in Standard, or to bundle the small files into larger archives before they are stored.