Skip to the page

Foundations: IAM, storage, databases, monitoring · core

S3 and CloudFront for web apps

S3 stores files as objects in private buckets, and CloudFront is the CDN in front of it: it caches content at edge locations near users, reads from the bucket through Origin Access Control, and serves private files through signed URLs or cookies.

The notes

What you must know

  • S3: buckets hold objects by key; very durable; new buckets block public access, disable ACLs (bucket owner enforced) and encrypt with SSE-S3 by default. Since April 2026 new buckets also have SSE-C (customer-provided keys) turned off by default.
  • Static site or SPA hosting: private bucket + CloudFront with Origin Access Control (OAC; the older OAI is legacy). For client-side routing, return /index.html for unknown paths (custom error response or a CloudFront Function).
  • Caching: CloudFront follows Cache-Control. Hashed asset files (app.3f9a1c.js) get max-age=31536000, immutable; index.html gets no-cache so new deploys show up.
  • Invalidations remove cached paths (the first 1,000 paths a month are free; a wildcard counts as one), but hashed file names avoid most of them.
  • Uploads and private downloads: presigned URLs (up to 7 days with IAM user credentials; shorter when signed with role credentials) or CloudFront signed URLs/cookies for many files.
  • Storage classes (Standard, Intelligent-Tiering, Glacier) and lifecycle rules cut cost for old objects.

The red pen

Common traps: mistake → fix

  • Mistake: Make the bucket public to host a website

    Fix: keep it private and serve through CloudFront with OAC.

  • Mistake: Invalidate /* on every deploy

    Fix: cache-bust with hashed file names; invalidate only index.html if needed.

  • Mistake: Cache index.html for a day

    Fix: users keep loading old bundles after a deploy.

Easy to hard

Questions interviewers ask, easy to hard

  1. How would you host a React or Vite SPA on AWS?
  2. How does CloudFront caching work? How do you deploy without users seeing old files?
  3. How do you serve private files (invoices) to logged-in users?
  4. OAC vs OAI?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview