Sub topic 16
Cost and performance considerations
This chapter assumes you know buckets, keys, storage classes, versioning, lifecycle rules, and multipart upload from earlier chapters. It also assumes you can read basic boto3 code. Here you will see where S3 charges come from, which design choices drive them, and how request patterns affect throughput.
The four cost drivers
An S3 bill splits into a few independent meters. Prices vary by Region and change over time, so check the current pricing page. The structure stays the same.
| Driver | What you pay for | Typical surprise |
|---|---|---|
| Storage | GB-months, priced per storage class | Old versions and abandoned multipart parts keep accruing |
| Requests | A price per 1,000 or 10,000 requests, by type and class | Millions of tiny objects make requests cost more than storage |
| Data transfer | Bytes leaving AWS or crossing Regions | Cross-Region copies and internet downloads |
| Management and extras | KMS calls, Intelligent-Tiering monitoring, Inventory, Storage Lens, replication | Small per-object fees multiplied by billions of objects |
Data sent into S3 from the internet is free. Data read from S3 by an EC2 instance in the same Region is free. Data leaving to the internet or to another Region is billed per GB.
Storage cost: class, duration and size rules
Colder classes have a lower per-GB price but add conditions that can make them more expensive than Standard for the wrong data.
- Minimum storage duration. Standard-IA and One Zone-IA charge for at least 30 days. Glacier Instant Retrieval and Glacier Flexible Retrieval charge for at least 90 days. Glacier Deep Archive charges for at least 180 days. Deleting or overwriting an object earlier still bills the remaining days.
- Minimum billable object size. The infrequent-access classes bill every object as at least 128 KB. Millions of 10 KB objects in Standard-IA cost more than the same data in Standard.
- Per-object overhead. Glacier Flexible Retrieval and Deep Archive add metadata overhead (about 40 KB per object, billed partly at Standard rates). Archiving very small objects individually rarely pays. Bundle them into larger archives first.
- Retrieval fees. IA and Glacier classes charge per GB retrieved. A "cold" dataset that is read weekly can cost more than it saves.
- Transition requests. Each lifecycle transition is a billed request. Moving 100 million small objects costs real money even if the savings are small.
If you cannot predict access patterns, S3 Intelligent-Tiering moves objects between access tiers automatically. It charges a monitoring fee per object, and objects under 128 KB are not auto-tiered. It suits larger objects with unknown or changing access. It does not suit tiny objects.
Hidden storage: versions and incomplete uploads
Two sources of storage cost are invisible in normal listings.
- Noncurrent versions. With versioning on, an overwrite or delete keeps the old data, and you pay for it. A file rewritten daily accumulates a full copy per day.
- Incomplete multipart uploads. Uploaded parts of a never-completed upload are billed but do not appear in
list_objects_v2.
Both are fixed with lifecycle rules. This configuration handles each one:
{
"Rules": [
{
"ID": "abort-stale-multipart-uploads",
"Status": "Enabled",
"Filter": { "Prefix": "" },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
},
{
"ID": "trim-old-versions",
"Status": "Enabled",
"Filter": { "Prefix": "" },
"NoncurrentVersionExpiration": {
"NoncurrentDays": 30,
"NewerNoncurrentVersions": 3
}
}
]
}Apply it with aws s3api put-bucket-lifecycle-configuration --bucket my-example-bucket-123456789012 --lifecycle-configuration file://lifecycle.json.
NewerNoncurrentVersions: 3 keeps the three most recent noncurrent versions. A noncurrent version is removed only when it is both older than 30 days and outside those three.
Request cost and object size
S3 charges per request, not per byte. A PUT of 1 KB and a PUT of 1 GB cost the same request fee. This has three consequences.
- Many small objects are expensive to write and read. Combine small records into larger files (for example, batch log lines into files of tens of MB) when your readers allow it. Analytics formats such as Parquet also help.
- LIST is a request too. Each
list_objects_v2call returns at most 1,000 keys. Listing a billion-key bucket repeatedly is slow and billed. For recurring audits, enable S3 Inventory, which delivers a scheduled report of all objects, instead of listing. - Requests differ in price. PUT, COPY, POST and LIST cost more per request than GET and SELECT-style reads. Lifecycle transitions into a colder class are priced like the destination class's PUT.
Performance: prefixes, parallelism and ranges
S3 scales request rates per prefix. Each prefix in a bucket supports at least 3,500 write requests (PUT, COPY, POST, DELETE) and 5,500 read requests (GET, HEAD) per second. A prefix is a key path segment, so spreading keys across several prefixes multiplies the ceiling. You do not need to randomize key names with hashes as older advice suggested. You only need to spread hot traffic over multiple prefixes if one prefix would exceed those rates.
If a client sees HTTP 503 SlowDown responses, it is exceeding the rate for a prefix while S3 scales up. Retry with exponential backoff. The AWS SDKs do this by default, and you can raise the attempts count in the client config.
Single-stream throughput is limited by one TCP connection. To go faster, use parallel connections:
import boto3
from boto3.s3.transfer import TransferConfig
s3 = boto3.client("s3")
bucket = "my-example-bucket-123456789012"
# Download a large object with 16 parallel ranged GETs of 16 MB each.
config = TransferConfig(
multipart_threshold=16 * 1024 * 1024,
multipart_chunksize=16 * 1024 * 1024,
max_concurrency=16,
)
s3.download_file(bucket, "backups/backup.tar", "backup-copy.tar", Config=config)
# Read only the first 1 KB of an object instead of all of it.
part = s3.get_object(
Bucket=bucket,
Key="reports/2026/report.csv",
Range="bytes=0-1023",
)
print(part["Body"].read().decode("utf-8", errors="replace"))Byte-range GETs let you read just the footer of a Parquet file or the header of a large archive. You pay for one request and only the bytes transferred out.
Other levers for latency and throughput:
- Same-Region compute. Put clients in the same Region as the bucket. This removes cross-Region transfer cost and cuts round-trip time.
- CloudFront. For repeated reads of the same objects by many users, a CDN cache serves most requests without touching S3 and lowers egress cost.
- S3 Transfer Acceleration. Routes uploads from distant clients through nearby AWS edge locations. It carries an extra per-GB fee, so test whether it helps your clients before enabling it.
- S3 Express One Zone. A directory bucket class for single-digit-millisecond latency in one Availability Zone. It has different durability trade-offs (one zone) and its own pricing.
Network path costs
An EC2 instance in a private subnet that reaches S3 through a NAT gateway pays NAT data-processing charges on every GB. A gateway VPC endpoint for S3 sends that traffic over the AWS network instead, at no hourly or per-GB charge for the endpoint. This is often the single largest easy saving for data-heavy workloads in private subnets.
Encryption and feature overhead
SSE-KMS makes a KMS API call for each object read and write, billed separately and subject to KMS request quotas. Enabling S3 Bucket Keys on the bucket lets S3 reuse a bucket-level key and can reduce KMS request costs substantially. SSE-S3 has no KMS charge.
Replication, event notifications, Inventory and Storage Lens each add small charges. Replication doubles storage (a copy in the destination) and adds Region-to-Region transfer for cross-Region replication. Enable them where they serve a requirement, not by default.
Finding where the money goes
- Turn on cost allocation tags or review Cost Explorer filtered to S3, grouped by usage type. Usage types such as
TimedStorage-ByteHrs,Requests-Tier1andDataTransfer-Out-Bytesshow which meter is growing. - Enable S3 Storage Lens for per-bucket and per-prefix metrics, including incomplete multipart bytes and noncurrent version bytes.
- Use S3 Storage Class Analysis on a bucket or prefix to see how often objects are read by age, before choosing lifecycle transition days.
- Compare estimated savings from a transition against its minimum duration, retrieval fees and transition request charges.
Summary of decisions
| Situation | Choice |
|---|---|
| Unknown or changing access pattern, large objects | Intelligent-Tiering |
| Rarely read, kept 30+ days, objects over 128 KB | Standard-IA, or Glacier tiers for longer retention |
| Millions of tiny objects | Batch them into larger objects before changing class |
| Versioned bucket with frequent overwrites | Expire noncurrent versions with a lifecycle rule |
| Slow single large transfer | Parallel multipart or ranged requests |
| Private subnet reading S3 heavily | Gateway VPC endpoint |
| Many users downloading the same objects | CloudFront in front of the bucket |
Exercise
A bucket has versioning enabled and holds 50 million objects averaging 20 KB. The team proposes a lifecycle rule moving all of them to Standard-IA after 30 days to save storage cost. Give two reasons the change may increase the bill, and one change that would reduce cost instead.
Show answer
First, Standard-IA bills each object as at least 128 KB, so 20 KB objects are billed at about six times their real size, which can erase the lower per-GB price. Second, 50 million transitions each incur a billed lifecycle request, and later reads incur retrieval fees. A better approach is to batch the small objects into larger files before storing them, or to leave them in Standard and add a lifecycle rule that expires noncurrent versions and aborts incomplete multipart uploads.
Exercise
A job running in a private subnet downloads several TB per day from an S3 bucket in the same Region, and the bill shows large NAT gateway data-processing charges. What do you change, and why does it help?
Show answer
Create a gateway VPC endpoint for S3 and add it to the subnet's route table. S3 traffic then bypasses the NAT gateway and stays on the AWS network, so the per-GB NAT processing charge no longer applies to it, and the gateway endpoint itself has no charge.