1---2name: s33description: Work with S3-compatible object storage with proper security, lifecycle policies, and access patterns.4---5
6## Public Access Control
7
8- Default deny public access—only open when explicitly needed (static hosting)
9- Bucket policy vs IAM: bucket policy for cross-account/public, IAM for same-account roles
10- Check both bucket-level AND account-level block settings—account can override bucket
11- For web assets, prefer CDN in front of bucket over direct public access
12
13## Presigned URLs
14
15- Set shortest expiration practical—minutes for immediate use, not days
16- URL is a bearer token—anyone with it has access; treat as secret
17- Specify HTTP method in signature—GET for download, PUT for upload
18- Include Content-Type for uploads—mismatch between signature and request causes 403
19- Generate server-side, never expose credentials to client
20
21## Lifecycle Rules
22
23- Transition to cheaper tiers for infrequent access—but check minimum storage duration penalties
24- Auto-delete for temp files, logs, old versions—prevents unbounded storage growth
25- Clean incomplete multipart uploads—accumulate invisibly; set abort rule (7 days typical)
26- Versioned buckets: separate rules for current vs noncurrent versions
27
28## Versioning Behavior
29
30- Enable before you need it—can't recover deleted objects without versioning
31- "Delete" creates delete marker—object hidden but versions remain; storage still consumed
32- Permanent deletion requires explicit version ID—without it, just adds marker
33- Noncurrent version expiration essential—otherwise old versions accumulate forever
34
35## Multipart Uploads
36
37- Required above 5GB, recommended above 100MB—single PUT has size limits
38- Incomplete uploads invisible in normal listings—consume storage silently
39- Abort incomplete uploads via lifecycle—or manually with `list-multipart-uploads`
40- Parallel part uploads for speed—parts can upload concurrently
41
42## CORS for Browser Access
43
44- Required for JavaScript direct upload/download—blocked without CORS headers
45- Specify exact origins—avoid wildcard `*` for authenticated requests
46- Expose headers that JavaScript needs to read—Content-Length, ETag, custom headers
47- AllowedMethods: GET for download, PUT for upload, DELETE if needed
48
49## Key Naming
50
51- Use prefixes like directories: `users/123/avatar.jpg`—but S3 is flat, not hierarchical
52- Avoid sequential prefixes for high throughput—`2024-01-01/file1` can hotspot
53- Random prefix or hash for write-heavy buckets—distributes across partitions
54- No leading slash—`/images/file.jpg` creates empty-string prefix
55
56## Cost Awareness
57
58- Request volume matters—many small files more expensive than few large files
59- Egress typically costly—CDN reduces egress by caching at edge
60- Minimum storage duration varies by tier—early deletion still charged full period
61- Lifecycle transitions have per-object cost—millions of tiny files expensive to transition
62
63## Replication
64
65- Cross-region for disaster recovery, same-region for compliance copies
66- Versioning required on both source and destination
67- Only new objects replicate—existing objects need manual copy or batch operation
68- Delete markers not replicated by default—explicitly enable if needed
69
70## Provider Differences
71
72- AWS S3: full feature set, most tools assume AWS behavior
73- Cloudflare R2: no egress fees, subset of features
74- Backblaze B2: S3-compatible API, different pricing model
75- MinIO: self-hosted, full S3 API compatibility
76- Check presigned URL compatibility—some providers have quirks