Sub topic 16
Cost and performance considerations
This chapter assumes you know buckets, keys, storage classes, versioning, lifecycle rules and multipart upload from the earlier chapters. It shows where S3 charges accumulate and how request patterns affect speed.
What you pay for
S3 bills along several separate dimensions. A bucket can be cheap on one and expensive on another.
| Cost driver | What triggers it | How to reduce it |
|---|---|---|
| Storage | GB stored per month, priced by storage class | Move cold data to cheaper classes with lifecycle rules |
| Requests | PUT, COPY, POST and LIST cost more per request than GET | Avoid many small objects and frequent listing |
| Retrieval | Reading from Standard-IA or Glacier classes | Keep frequently read data in Standard |
| Data transfer | Data leaving AWS or crossing Regions | Keep compute in the same Region as the bucket |
| Hidden storage | Old versions and incomplete multipart uploads | Expire them with lifecycle rules |
Uploading data into S3 is free. Reading it from an EC2 instance in the same Region is also free. Sending it to the internet or to another Region is not. Check the current S3 pricing page for rates, since they vary by Region.
Cheaper classes can cost more
Infrequent-access and archive classes lower the storage price but add conditions. Standard-IA and One Zone-IA charge for at least 128 KB per object and for at least 30 days of storage. Glacier classes have longer minimum durations and retrieval fees. A bucket of millions of 5 KB files moved to Standard-IA can cost more than it did in Standard. Lifecycle transitions are billed per object, so they add up for small objects.
Use S3 Intelligent-Tiering when the access pattern is unknown. It moves objects between tiers automatically and charges a small monitoring fee per object.
Clean up hidden storage
Versioning keeps every old version, and each one is billed. Unfinished multipart uploads also store parts that never show up in a normal object listing. This lifecycle rule handles both:
{
"Rules": [
{
"ID": "clean-up-hidden-storage",
"Status": "Enabled",
"Filter": { "Prefix": "" },
"NoncurrentVersionExpiration": { "NoncurrentDays": 30 },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
}
]
}Save it as cleanup.json and apply it:
aws s3api put-bucket-lifecycle-configuration \
--bucket my-example-bucket-123456789012 \
--lifecycle-configuration file://cleanup.jsonThis call replaces the bucket's whole lifecycle configuration. Merge these rules into any rules you already have, or the old ones are lost.
Performance: spread the load
S3 scales request rates per prefix. Each prefix supports at least 3,500 write requests (PUT, COPY, POST, DELETE) and 5,500 read requests (GET, HEAD) per second. A prefix is not a fixed object. You can add more prefixes, and the limit applies to each one. Practical rules:
- Run many requests in parallel instead of one after another.
- Spread very hot workloads across several prefixes.
- Use multipart upload for large files. The parts upload in parallel.
- Use ranged GETs, which send a
Rangeheader, to download large objects in parallel or to read only part of an object. - Retry on HTTP 503 Slow Down responses. The SDKs back off automatically.
For users far from the bucket's Region, S3 Transfer Acceleration speeds up transfers over long distances. For content read repeatedly by many users, put CloudFront in front of the bucket. This lowers latency and often lowers transfer cost.
Exercise
A bucket holds 40 million log files of 4 KB each. A teammate proposes moving them to Standard-IA after 30 days to save money. Why might this raise the bill, and what would you check or change first?
Show answer
Standard-IA bills a minimum of 128 KB per object, so each 4 KB file is charged as 128 KB, and each transition also incurs a per-object request charge. Storage could cost more than in Standard. Check the real storage and request costs first. Then combine the logs into larger files before transition, or leave them in Standard or Intelligent-Tiering and expire them when no longer needed.