S3 Object Storage
Store any file at infinite scale — buckets, objects, versioning, lifecycle rules, and static website hosting
Skills taught: aws.s3, aws.s3-buckets, aws.s3-versioning, aws.s3-lifecycle, aws.s3-website, aws.s3-presigned-urls
S3 — the foundation of AWS
S3 (Simple Storage Service) is where everything lives in AWS. It stores images, videos, backups, log files, static websites, machine learning datasets, and CloudFormation templates. It has 11 nines of durability (99.999999999%) — meaning if you store 10 million objects, you might lose one object every 10,000 years. It's the backbone of the internet: Netflix, Airbnb, and most of the web stores files on S3.
Buckets and objects
# S3 has two concepts: BUCKETS (containers) and OBJECTS (files)
# Bucket names must be globally unique across ALL AWS accounts
# Objects are stored with a 'key' (the path/filename)
# Create a bucket
aws s3 mb s3://myapp-uploads-prod-2026 # globally unique name
# Bucket naming rules: lowercase, letters/numbers/hyphens, 3-63 chars
# Upload objects
aws s3 cp photo.jpg s3://myapp-uploads-prod-2026/photos/photo.jpg
aws s3 cp ./uploads/ s3://myapp-uploads-prod-2026/uploads/ --recursive
aws s3 sync ./dist/ s3://myapp-uploads-prod-2026/website/ --delete
# List objects
aws s3 ls s3://myapp-uploads-prod-2026/
aws s3 ls s3://myapp-uploads-prod-2026/photos/ --recursive --human-readable
# Download
aws s3 cp s3://myapp-uploads-prod-2026/photo.jpg ./local-copy.jpg
# Delete
aws s3 rm s3://myapp-uploads-prod-2026/old-file.txt
aws s3 rm s3://myapp-uploads-prod-2026/old-folder/ --recursive
# Object URL format (when public):
# https://myapp-uploads-prod-2026.s3.ap-south-1.amazonaws.com/photos/photo.jpg
# https://myapp-uploads-prod-2026.s3.amazonaws.com/photos/photo.jpg
S3 storage classes — pay only for what you need
S3 Standard → $0.023/GB/month Frequently accessed data
Availability: 99.99%
Use: app uploads, user photos, active data
S3 Intelligent-Tiering → auto-moves between Standard and Infrequent Access
Use: unpredictable access patterns
Monitoring fee: $0.0025 per 1,000 objects
S3 Standard-IA → $0.0125/GB/month Infrequently accessed
(Infrequent Access) Retrieval fee: $0.01/GB
Use: disaster recovery, backups accessed rarely
S3 Glacier Instant → $0.004/GB/month Archives, millisecond retrieval
S3 Glacier Flexible → $0.0036/GB/month Archives, minutes-to-hours retrieval
S3 Glacier Deep Archive → $0.00099/GB/month Coldest storage, 12h retrieval
Rule of thumb:
- Active data → Standard
- Monthly backups → Standard-IA
- Compliance archives → Glacier Deep Archive
Versioning and lifecycle rules
# Enable versioning (protects against accidental deletion/overwrites)
aws s3api put-bucket-versioning \
--bucket myapp-uploads-prod-2026 \
--versioning-configuration Status=Enabled
# With versioning enabled:
# - Overwriting an object creates a new version, not an overwrite
# - Deleting creates a 'delete marker', object is recoverable
# - Restore by deleting the delete marker
# Lifecycle rules — automatically transition/expire objects
# Via console or this JSON applied to the bucket:
{
"Rules": [{
"ID": "Transition logs to Glacier",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" },
{ "Days": 90, "StorageClass": "GLACIER" }
],
"Expiration": { "Days": 365 } // delete after 1 year
}]
}
Static website hosting on S3
# 1. Create bucket with same name as domain
aws s3 mb s3://mysite.com
# 2. Enable static website hosting
aws s3 website s3://mysite.com/ \
--index-document index.html \
--error-document error.html
# 3. Set bucket policy for public read
aws s3api put-bucket-policy --bucket mysite.com --policy '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mysite.com/*"
}]
}'
# 4. Deploy your site
aws s3 sync ./dist s3://mysite.com/ --delete
# Website URL: http://mysite.com.s3-website-ap-south-1.amazonaws.com
# Then point your domain DNS CNAME to this URL
# For HTTPS: use CloudFront in front of S3 (lesson 11)
# Cost: $0.023/GB storage + $0.0004/10k GET requests
# A typical small site: < $1/month
Tip: Pre-signed URLs let users upload directly to S3 without exposing your credentials. Your server generates a temporary URL (valid for N minutes) that the browser uses to PUT directly to S3 — bypassing your server entirely. This means large file uploads don't pass through your server, saving bandwidth and cost. Use getSignedUrl with PutObjectCommand from the AWS SDK.
Frequently Asked Questions
What's the difference between S3 and EBS (Elastic Block Store)?
S3 is object storage — you access files via API calls (HTTP GET/PUT), ideal for storing arbitrary files at scale. EBS is block storage — it's like a hard drive attached to an EC2 instance, accessible as a filesystem. Use S3 for file storage, backups, and static assets. Use EBS as the disk for an EC2 instance that needs a filesystem.