AWS S3 — Storage ও CDN

লেসন ৩১ / ৩৮

📦 S3 Highlights

  • 11 nines durability
  • Unlimited storage
  • $0.023/GB standard
  • Globally unique bucket name

🛠️ Create

1. S3 → Create bucket
2. Region: ap-south-1
3. Block public: ON (default)
4. Versioning: enable
5. Encryption: SSE-S3 (free)

aws s3 mb s3://my-bucket

📤 Operations

aws s3 cp file s3://bucket/
aws s3 sync ./local s3://bucket/
aws s3 ls s3://bucket/
aws s3 rm s3://bucket/file

🐍 Python + Presigned

import boto3
s3 = boto3.client("s3")

# Upload
s3.upload_file("local.jpg", "bucket", "photo.jpg")

# Presigned URL (temp access)
url = s3.generate_presigned_url(
    "get_object",
    Params={"Bucket":"b", "Key":"x"},
    ExpiresIn=3600
)

🌐 Static Website

Properties → Static hosting → Enable
Bucket Policy — allow s3:GetObject
URL: bucket.s3-website-region.amazonaws.com

🚀 + CloudFront

1. CloudFront → Create distribution
2. Origin: S3 bucket
3. OAC — restrict bucket to CF
4. SSL: ACM cert (free, us-east-1!)
5. Custom domain (CNAME)

→ Global CDN, HTTPS, ~$1/mo

♻️ Lifecycle Rule

30d → Standard-IA (cheaper)
90d → Glacier
365d → Deep Archive ($0.001/GB)
2555d → auto-delete

💰 Storage Class Cost/GB

Standard    $0.023
Standard-IA $0.0125
Glacier IR  $0.004
Glacier F   $0.0036
Deep Arch   $0.00099

📦 Upload Pattern

// Client → presigned URL (backend) → direct to S3
// Backend bandwidth zero, scalable
const {url} = await fetch("/api/upload-url");
await fetch(url, {method:"PUT", body: file});

🎓 মূল কথা ⭐

S3 = unlimited durable। CloudFront+S3 = static site $1/mo। Lifecycle → Glacier = 95% cost cut। Presigned upload = scalable pattern।