Sub topic 3
Choosing an S3 Storage Class
Assume you understand AWS Regions, IAM roles, and basic CLI or Python use. S3 storage classes trade storage price against retrieval cost, latency, and availability.
Choosing a storage class
Use S3 Standard for frequently accessed data. Standard-IA costs less to store but charges retrieval fees and has a 30-day minimum. One Zone-IA is cheaper, but stores data in one Availability Zone. Glacier Flexible Retrieval and Deep Archive suit backups that can wait for retrieval. Intelligent-Tiering moves objects automatically when access changes, for a small monitoring charge.
| Access pattern | Typical choice | Main trade-off |
|---|---|---|
| Frequent access | Standard | Higher storage price |
| Infrequent access | Standard-IA | Retrieval charge and minimum duration |
| Long-term archive | Glacier Flexible Retrieval or Deep Archive | Slower retrieval |
Versioning and recovering from mistakes
Versioning stores multiple versions of an object under the same key. A normal delete adds a delete marker instead of immediately removing the data. You can remove the marker or request a specific version ID to recover an object. Versioning increases storage use, so lifecycle rules should manage old versions.
Automating transitions and expiration
A lifecycle rule selects objects by prefix, tag, or both. It can transition objects to cheaper classes, delete current objects, and expire noncurrent versions. For example, logs might move to Standard-IA after 30 days and Glacier after 90 days.
{
"Rules": [
{
"ID": "archive-logs",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" },
{ "Days": 90, "StorageClass": "GLACIER" }
],
"Expiration": { "Days": 365 }
}
]
}Uploading large objects
Multipart upload divides a large object into parts. Parts upload independently, so failed parts can be retried. Boto3 automatically uses multipart transfer when configured:
import boto3
from boto3.s3.transfer import TransferConfig
s3 = boto3.client("s3")
config = TransferConfig(
multipart_threshold=64 * 1024 * 1024,
multipart_chunksize=64 * 1024 * 1024,
)
s3.upload_file("backup.tar", "example-bucket", "backups/backup.tar",
Config=config)Abort incomplete uploads with a lifecycle rule to avoid paying for abandoned parts.
Notifications and replication
S3 can publish object-created events to SQS, SNS, Lambda, or EventBridge. Notifications are asynchronous, so consumers must tolerate retries and duplicate events.
Replication copies objects between buckets, including across Regions. Versioning must be enabled on both buckets. Replication needs an IAM role and can increase request, storage, and data-transfer costs.
Cost and performance considerations
Measure storage, request, retrieval, transfer, and monitoring charges together. Use prefixes that match common list operations, cache hot data when appropriate, and choose multipart part sizes that balance retry cost against concurrency.
Exercise
A report is read often for two weeks, then rarely for one year. What design should you consider?
Show answer
Keep it in Standard initially, then use a lifecycle transition to an infrequent-access or archival class, while retaining versioning only if recovery is required.