S3 is usually the first AWS service students touch, and most of us only ever use upload, download and "make it public". Here are nine S3 tricks that save time, money and the occasional data leak.
Sharing and access
1. Share a private file with a presigned URL
Don't make a bucket public to share one file. Generate a link that expires:
aws s3 presign s3://my-bucket/report.pdf --expires-in 3600
Anyone with the link can download that one object for an hour. With IAM user credentials the maximum is 7 days; with temporary credentials the link dies when the credentials do.
2. Host a website without turning off Block Public Access
S3 website endpoints are HTTP-only and need a public bucket. Instead, keep the bucket private and put CloudFront in front of it with Origin Access Control. You get HTTPS, caching and a private bucket. Amplify Hosting does the same setup for you in a few clicks.
3. Copy without downloading
aws s3 cp and aws s3 sync between two buckets copy server-side; the data never touches your laptop:
aws s3 sync s3://old-bucket s3://new-bucket --dryrun
Remove --dryrun once the list looks right.
Cost
4. Let lifecycle rules do the cleanup
A lifecycle rule can move old objects to cheaper storage classes, delete them after N days, expire old versions, and abort incomplete multipart uploads. Set it once on any bucket that collects logs, exports or build artifacts.
5. Use Intelligent-Tiering when you don't know the access pattern
S3 Intelligent-Tiering moves objects between access tiers automatically, with no retrieval fees. There's a small monitoring charge per object, and objects under 128 KB aren't auto-tiered, so it suits larger files.
6. Find what's eating storage with Storage Lens
S3 Storage Lens has a free dashboard showing storage by bucket, the share of noncurrent versions, and incomplete multipart upload bytes. It's the fastest way to find the bucket that's quietly growing.
Safety
7. Turn on versioning before you need it
With versioning on, an overwrite or delete keeps the previous version, so aws s3 sync --delete gone wrong becomes recoverable. Pair it with a lifecycle rule that expires noncurrent versions, or old versions pile up.
8. Keep Block Public Access on
Since April 2023, new buckets have Block Public Access on by default. If something returns "Access Denied", fix the IAM policy or use a presigned URL. Turning off Block Public Access is almost never the right fix.
9. Download part of a file
Need the first few lines of a huge log or CSV? Fetch a byte range instead of the whole object:
aws s3api get-object --bucket my-bucket --key big.csv --range bytes=0-1023 head.csv
Quick checklist
- [ ] Presigned URLs instead of public buckets
- [ ] CloudFront or Amplify for websites
- [ ] Lifecycle rules on log and export buckets
- [ ] Versioning on anything you'd hate to lose
- [ ] Block Public Access on everywhere
- [ ] Storage Lens checked once a month
Which of these did you not know? And what's your favourite S3 trick that isn't on this list?
Loading article