Sub topic 10
Choosing a storage class
Every S3 object has a storage class. The class sets what you pay to store the object, what you pay to read it, how quickly you can get it back, and how many Availability Zones hold it. This chapter assumes you can create buckets and upload objects with the CLI or boto3, and that you know what a lifecycle rule is, though the next chapter covers writing them in detail.
What a storage class changes
All classes except One Zone-IA and the single-zone Express class store data across at least three Availability Zones. Durability is designed for 99.999999999% (eleven nines) in every class. What differs is the following:
- Storage price per GB-month. Colder classes cost less.
- Retrieval fee per GB. Infrequent-access and archive classes charge to read data. Standard and Intelligent-Tiering do not.
- Minimum storage duration. If you delete or overwrite an object early, you are billed for the remaining days.
- Minimum billable object size. Some classes bill small objects as if they were 128 KB.
- First-byte latency. Most classes return data in milliseconds. Two archive classes need a restore step first.
- Availability. The design target drops from 99.99% in Standard to 99.9% in the infrequent-access classes and 99.5% in One Zone-IA.
You choose a class per object, not per bucket. Uploads default to STANDARD unless you say otherwise.
The classes compared
| Class | API value | Retrieval | Minimum duration | Notes |
|---|---|---|---|---|
| Standard | `STANDARD` | Milliseconds, no fee | None | Default for active data |
| Intelligent-Tiering | `INTELLIGENT_TIERING` | Milliseconds in the default tiers, no retrieval fee | None | Monitoring fee per object; moves data between tiers automatically |
| Standard-IA | `STANDARD_IA` | Milliseconds, per-GB fee | 30 days | 128 KB minimum billable size |
| One Zone-IA | `ONEZONE_IA` | Milliseconds, per-GB fee | 30 days | One Availability Zone only |
| Glacier Instant Retrieval | `GLACIER_IR` | Milliseconds, higher per-GB fee | 90 days | 128 KB minimum billable size |
| Glacier Flexible Retrieval | `GLACIER` | Minutes to hours after a restore | 90 days | Per-object metadata overhead |
| Glacier Deep Archive | `DEEP_ARCHIVE` | Hours after a restore | 180 days | Lowest storage price |
Express One Zone is a separate class used with directory buckets for single-digit-millisecond latency. It is aimed at latency-sensitive workloads and is outside this chapter's decision path.
Walking through the decision
Standard
Use Standard for data that applications read regularly, such as website assets, active datasets and recent logs. It has no retrieval fee and no minimum duration, so it is the safe default. You only pay more than necessary if the data goes cold and stays in Standard.
Intelligent-Tiering
Intelligent-Tiering watches each object's access pattern and moves it between tiers for you. An object that is not read for 30 days moves to the Infrequent Access tier. After 90 days without a read it moves to Archive Instant Access. Reading it moves it back to Frequent Access. You can also enable the optional Archive Access and Deep Archive Access tiers, which behave like the Glacier classes and need a restore.
There is no retrieval fee, but you pay a small monitoring and automation charge per object. Objects smaller than 128 KB are never moved and are billed at the Frequent Access rate. This class suits data with unpredictable access and objects that are large enough for the monitoring fee to be worth it. It is a poor fit for billions of tiny objects.
Standard-IA and One Zone-IA
These classes cost less to store than Standard but charge per GB to read. They suit data that is kept for a long time and read rarely, such as backups and older reports.
One Zone-IA keeps data in a single Availability Zone, so an event that destroys that zone loses the data. Use it only for data you can regenerate or that already has a copy elsewhere.
The Glacier classes
- Glacier Instant Retrieval returns data in milliseconds. It is cheaper to store than Standard-IA and costs more to read, so it suits archives touched about once a quarter, such as medical images.
- Glacier Flexible Retrieval requires a restore. Expedited restores take 1 to 5 minutes, Standard restores 3 to 5 hours, and Bulk restores 5 to 12 hours.
- Glacier Deep Archive has the lowest storage price. Standard restores complete within 12 hours and Bulk restores within 48 hours. It suits compliance records kept for years.
Estimating break-even with an example
These prices are illustrative (roughly US East N. Virginia list prices). Check the S3 pricing page for your Region before deciding.
- Standard: $0.023 per GB-month.
- Standard-IA: $0.0125 per GB-month, plus $0.01 per GB retrieved.
Standard-IA saves about $0.0105 per GB each month. Reading the whole object once costs $0.01 per GB. So if you read an object's full contents about once a month or more, Standard-IA costs the same as or more than Standard. If you read it a few times a year, Standard-IA wins clearly.
Two things shift this calculation:
- A 40 KB object in Standard-IA is billed as 128 KB, which can make it more expensive than Standard.
- Deleting a Standard-IA object after 10 days still bills you for 30 days.
Request charges also differ by class. Moving many small objects between classes pays a per-request transition charge, which can exceed the storage saving.
Setting the class when you upload
Pass the class with the upload. This example sends an archive to Glacier Instant Retrieval.
import boto3
s3 = boto3.client("s3")
bucket = "my-example-bucket-123456789012"
s3.upload_file(
"backup.tar",
bucket,
"backups/backup.tar",
ExtraArgs={"StorageClass": "GLACIER_IR"},
)
head = s3.head_object(Bucket=bucket, Key="backups/backup.tar")
print(head.get("StorageClass", "STANDARD"))head_object omits the StorageClass field for Standard objects, which is why the code supplies a default.
To change the class of an existing object, copy it onto itself with a new class. For a Standard-to-colder move at scale, a lifecycle rule is easier.
aws s3 cp s3://my-example-bucket-123456789012/backups/backup.tar \
s3://my-example-bucket-123456789012/backups/backup.tar \
--storage-class STANDARD_IARestoring archived objects
Objects in Glacier Flexible Retrieval and Deep Archive cannot be read directly. A GetObject call fails with InvalidObjectState. You request a restore, which creates a temporary readable copy for a number of days. The archived object stays in its class.
import boto3
s3 = boto3.client("s3")
bucket = "my-example-bucket-123456789012"
key = "archive/2019/records.tar"
s3.restore_object(
Bucket=bucket,
Key=key,
RestoreRequest={
"Days": 7,
"GlacierJobParameters": {"Tier": "Standard"},
},
)
head = s3.head_object(Bucket=bucket, Key=key)
print(head.get("Restore"))While the restore runs, Restore reads ongoing-request="true". When it finishes, it reads ongoing-request="false" with an expiry date, and you can download the object until that date. Glacier Instant Retrieval and the Intelligent-Tiering Archive Instant Access tier need no restore.
Common mistakes
- Putting small objects in IA or Glacier classes. The 128 KB minimum billable size and per-object overhead can cost more than Standard. Combine small files into larger archives first.
- Choosing a cold class for data you still read. Retrieval fees, and for archives the restore delay, appear later and often unexpectedly.
- Using One Zone-IA as the only copy of important data. A single-zone loss is not covered by the eleven-nines figure.
- Forgetting that lifecycle transitions only move colder. A lifecycle rule cannot move an object from Standard-IA back to Standard. To move up, copy the object or restore it.
- Ignoring request costs when migrating. Transitioning millions of objects incurs a per-1,000-object request charge.
Exercise
A bucket holds 2 million objects of about 20 KB each. Reads are rare and unpredictable. A teammate proposes moving everything to Intelligent-Tiering to save money. Is that a good idea, and what would you do instead?
Show answer
Probably not. Objects under 128 KB are never moved to a cheaper tier in Intelligent-Tiering and are billed at the Frequent Access rate, while the monitoring fee may still apply, so there is little saving. Standard-IA and the Glacier Instant Retrieval class would also bill each object as 128 KB. A better approach is to combine the small objects into larger archives, for example one tar file per day, and then apply an infrequent-access or archive class to those archives.
Exercise
You upload a backup to Glacier Flexible Retrieval, and ten days later you need to read it today. What happens if you call GetObject, and what steps do you take to read it?
Show answer
GetObject fails with InvalidObjectState because the object is archived. Call restoreobject (or aws s3api restore-object) with a number of days and a retrieval tier, such as Expedited for minutes or Standard for hours. Poll headobject until the Restore field shows ongoing-request="false", then download the object before the expiry date. The 90-day minimum duration still applies to the archived copy.