Amazon S3 for Developers
Overview
Amazon S3 is object storage with virtually unlimited capacity and 11 nines of durability. Developers use it for user uploads, static websites, data lakes, build artifacts and event-driven processing.
Treat S3 like a huge self-storage facility with a clerk at the counter. Each object lives in a bucket under a key (its label). You can hand a visitor a temporary pre-signed URL (a guest pass) that lets them drop off or collect one box without giving them your keys to the whole facility.
Developer-focused S3 topics include presigned URLs, multipart uploads, event notifications, versioning, encryption options, CORS and request-rate behaviour.
Key Concepts
- Objects are 0 bytes to 5 TB; a single PUT is limited to 5 GB; use multipart upload (recommended above 100 MB, required above 5 GB; parts 5 MB-5 GB, up to 10,000 parts).
- Pre-signed URLs grant time-limited access using the signer's permissions; they stop working when the signer's credentials expire.
- S3 is strongly consistent for reads after writes and list operations.
- Request rates scale to at least 3,500 PUT/POST/DELETE and 5,500 GET/HEAD per second per prefix.
- Event notifications go to Lambda, SQS, SNS or EventBridge (richer filtering, more targets).
- Versioning protects against overwrites and deletes; deletes add a delete marker.
- Encryption at rest: SSE-S3 (default), SSE-KMS (audit/key control; KMS request quotas apply), SSE-C (customer key), plus client-side.
- CORS configuration on the bucket is needed for browsers calling S3 from another origin.
Detailed Notes
Pre-signed URLs
import boto3
s3 = boto3.client("s3", region_name="eu-west-1")
get_url = s3.generate_presigned_url(
"get_object", Params={"Bucket": "docs-bkt", "Key": "report.pdf"}, ExpiresIn=900)
put_url = s3.generate_presigned_url(
"put_object",
Params={"Bucket": "docs-bkt", "Key": "uploads/u123/photo.jpg", "ContentType": "image/jpeg"},
ExpiresIn=300)
The browser then uploads directly: fetch(putUrl, { method: "PUT", body: file, headers: { "Content-Type": "image/jpeg" } }). This offloads bandwidth from your servers. The URL carries the permissions of the identity that signed it, so use a role scoped to the needed prefix. Pre-signed POST allows size and type conditions.
Multipart upload
aws s3 cp bigfile.iso s3://my-bucket/ # CLI handles multipart automatically
aws s3api list-multipart-uploads --bucket my-bucket
Parts upload in parallel and can be retried individually. Abort incomplete uploads with a lifecycle rule (AbortIncompleteMultipartUpload) because leftover parts incur storage cost.
Event notifications
Resources:
ThumbFn:
Type: AWS::Serverless::Function
Properties:
Runtime: python3.12
Handler: app.handler
Events:
Upload:
Type: S3
Properties:
Bucket: !Ref UploadsBucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- { Name: prefix, Value: uploads/ }
- { Name: suffix, Value: .jpg }
Avoid recursive triggers: if the function writes results into the same bucket and prefix it triggers itself, so write elsewhere or use prefix filters. S3 notifications are at-least-once, so make processing idempotent.
Select and query
Use Range header byte-range fetches to download part of an object or parallelise downloads. S3 Select (limited availability for new customers) and Athena query objects in place.
Versioning and lifecycle
| Feature | Purpose |
|---|---|
| Versioning | Recover from overwrite/delete; required for replication |
| Lifecycle | Transition to cheaper classes or expire objects |
| Object Lock | WORM retention (compliance/governance modes) |
| MFA Delete | Extra protection on permanent deletes |
Encryption notes
- Since January 2023 all new objects are encrypted with SSE-S3 by default.
- SSE-KMS calls count toward KMS request quotas (5,500-30,000 per second depending on Region), so use S3 Bucket Keys to cut KMS calls and cost.
- Enforce TLS and encryption with a bucket policy using
aws:SecureTransport.
Static websites and CORS
[{
"AllowedOrigins": ["https://app.example.com"],
"AllowedMethods": ["GET", "PUT"],
"AllowedHeaders": ["*"],
"MaxAgeSeconds": 3000
}]
Node.js upload with progress
import { Upload } from "@aws-sdk/lib-storage";
import { S3Client } from "@aws-sdk/client-s3";
const up = new Upload({
client: new S3Client({}),
params: { Bucket: "docs-bkt", Key: "big.zip", Body: stream },
partSize: 10 * 1024 * 1024, queueSize: 4,
});
up.on("httpUploadProgress", (p) => console.log(p.loaded, p.total));
await up.done();
Consistency, versioning and event notifications
S3 provides strong read-after-write consistency for new objects, overwrites, deletes and listings. Enable versioning to protect against accidental overwrite; deletes then add a delete marker and previous versions stay recoverable (use VersionId). Object Lock adds write-once retention for compliance.
| Feature | What it does | Developer note |
|---|---|---|
| Event notifications | Emit s3:ObjectCreated:* to Lambda, SQS, SNS or EventBridge | EventBridge gives filtering, archive and many targets |
| Pre-signed URLs | Time-limited access with the signer's permissions | Expire in up to 7 days (IAM user) or the role session lifetime |
| CORS | Browser cross-origin rules on the bucket | Needed for direct browser uploads |
| S3 Select / Athena | Query inside objects | Reduces data transferred |
| Transfer Acceleration | Edge-optimised uploads | Different endpoint, extra cost |
[{"AllowedOrigins": ["https://app.example.com"], "AllowedMethods": ["PUT", "GET"],
"AllowedHeaders": ["*"], "ExposeHeaders": ["ETag"], "MaxAgeSeconds": 3000}]
Protecting data
Block Public Access should stay on at account level. Use bucket policies with aws:SecureTransport, encrypt with SSE-KMS and Bucket Keys, and grant cross-account access through bucket policies plus IAM. For large objects, use multipart upload (required above 5 GB, recommended above 100 MB), parallel parts and a lifecycle rule that aborts incomplete uploads. Use byte-range fetches (Range: bytes=0-999999) to read parts of large objects in parallel.
Real World Example
A photo-sharing app used to proxy uploads through its API servers, saturating bandwidth. Now the API returns a pre-signed PUT URL scoped to uploads/<userId>/, the browser uploads straight to S3 (using multipart for large videos), and an S3 event to EventBridge triggers a Lambda that generates thumbnails into a separate prefix. Server bandwidth costs dropped by 80% and uploads became faster for users.
Architecture Diagram
The API issues a pre-signed URL; S3 events trigger asynchronous processing.
- 1The browser asks the API for an upload URL.
- 2The API signs a short-lived pre-signed URL with a scoped role.
- 3The browser uploads directly to S3.
- 4The object-created event triggers the processing function.
Best Practices
- ✓Use pre-signed URLs for direct client uploads and downloads with short expirations.
- ✓Add a lifecycle rule to abort incomplete multipart uploads.
- ✓Write function output to a different prefix or bucket to avoid recursion.
- ✓Enable S3 Bucket Keys with SSE-KMS and versioning for important data.
- ✓Spread heavy workloads across prefixes and use byte-range parallel GETs.
Common Interview Questions
Exam Tips
DVA-C02 focus
- Temporary access to a private object -> pre-signed URL.
- Large file upload reliability and speed -> multipart upload (and Transfer Acceleration for distance).
- SSE-KMS throttling -> S3 Bucket Keys / request quota increase.
- Browser cross-origin failures -> CORS configuration on the bucket.
Finished this lesson?
0 of 46 lessons done · 0% of the course

