Skip to content
watch on youtubeThe notes below cover everything in the video. Find it in the playlist on our channel.Open the YouTube channel
Lesson 5 of 1010 min video

S3: Storage and a Static Website

Learn S3 buckets and objects, the AWS CLI for S3, storage classes and lifecycle rules, static website hosting, bucket policies and CloudFront.

Video chapters

  1. 00:00Intro
  2. 00:43How S3 thinks
  3. 01:53Step 1: Create a secure bucket
  4. 02:45Step 2: S3 from the command line
  5. 03:55Pay less: storage classes and lifecycle
  6. 04:51Step 3: Host a static website
  7. 06:15Step 4: Allow public reads, only for this site
  8. 07:04The professional way: CloudFront in front
  9. 08:19S3 mistakes that make the news
  10. 09:32You can store anything, and host a site

S3 is AWS's object storage, and it shows up in almost every architecture: backups, user uploads, logs, data lakes, and websites. In this episode you create a secure bucket, use it from the CLI, and host a static website with no server at all.

What you need

  • AWS account + CLI from Episode 3
  • A tiny website: an index.html and an error.html

How S3 thinks

First, how S3 thinks. It's not a hard drive. It's object storage, and there are a few ideas to get right.

Files go into buckets. A bucket's name must be unique across all of AWS, not just your account. So names like test or website are already taken. Add your project and a number.

Each file is an object: the data, plus some metadata, like its content type. A single object can be up to five terabytes.

Every object has a key, its full name. Here's the interesting part: S3 has no real folders. A key like images slash logo dot png is just a name that happens to contain a slash. The console shows it as a folder to make life easier.

Each bucket lives in one region, which you choose when you create it.

And S3 is designed for eleven nines of durability, meaning your objects are stored redundantly across multiple devices and facilities. Durability isn't the same as protection from mistakes, though. If you delete a file, it's gone, unless you've turned on versioning, which we'll do in a moment.

Quick reference

  • Bucket: A container. Its name is unique across ALL of AWS
  • Object: A file + metadata, up to 5 TB each
  • Key: The object's full name, like a path
  • Region: A bucket lives in one region you choose
  • Durability: Designed for 99.999999999% (11 nines)

bucket: acme-site-2026

index.html
error.html
css/style.css
images/logo.png

key = "images/logo.png"
no real folders: "/" is just
part of the name

Step 1 · Create a secure bucket

Step one: create a bucket. Open the S3 console, and click create bucket.

Choose a name. Lowercase letters, numbers and dashes, and unique across all of AWS.

Pick your home region.

Leave block all public access turned on. This is the switch that prevents accidental public buckets, and it's on by default for good reason.

Enable bucket versioning. Now, when you overwrite or delete a file, the previous version is kept, and you can restore it. It's a simple safety net against mistakes and ransomware.

Default encryption with S3 managed keys is already on. Add your project tag, and create the bucket.

Notice the philosophy: everything starts private and protected. You open things up only on purpose, and as little as possible.

Quick reference

  1. S3 console → Create bucket
  2. Name: acme-site-2026 (unique, lowercase)
  3. Region: your home region
  4. Block all public access: ON (default)
  5. Bucket versioning: Enable
  6. Encryption: SSE-S3 (default) · Tag project
Tip: Private by default. You open things up only on purpose.

Step 2 · S3 from the command line

Step two: using S3 from the command line, with the CLI we set up in episode three. aws s3 ls lists your buckets.

aws s3 cp copies a file. Here, a report goes into the docs path of our bucket.

And ls with a bucket path lists what's inside.

aws s3 sync is the one you'll use most. It compares a local folder with a bucket, and uploads only what changed. Deploying a website, or backing up a folder, is a single sync command.

And presign creates a temporary link to a private object. Here, it's valid for one hour.

Anyone with that link can download the file until it expires, without an AWS account. This is how apps share private files safely, like an invoice download.

But treat presigned links like temporary passwords. Don't post them publicly, and keep the expiry short.

Everything you just did in the terminal, you could also do in the console, by clicking. The difference is that commands can go into a script, a pipeline, or documentation, and run exactly the same way next time.

Quick reference

aws s3 ls                                   # list your buckets
aws s3 cp report.pdf s3://acme-site-2026/docs/
aws s3 ls s3://acme-site-2026/docs/
aws s3 sync ./site s3://acme-site-2026      # upload only what changed
aws s3 presign s3://acme-site-2026/docs/report.pdf --expires-in 3600
https://acme-site-2026.s3.amazonaws.com/docs/report.pdf?X-Amz-...
Tip: A presigned link is a temporary key. Anyone with it can download.

Pay less: storage classes and lifecycle

Storage is cheap, but at scale it adds up, so S3 offers different storage classes.

Standard is the default, for data you use often.

Standard infrequent access stores data more cheaply, but charges a fee each time you read it. Good for backups you rarely open.

The Glacier classes are for archives. They're the cheapest to store, but slower or more expensive to read back, depending on which one you choose.

If you don't know how often data will be used, Intelligent-Tiering moves objects between tiers for you, based on how they're actually accessed.

And lifecycle rules automate it all. For example: move anything under logs to infrequent access after thirty days, and delete it after a year. Set it once, and your storage bill stays under control forever. Check current prices on the S3 pricing page, because they vary by region.

Quick reference

  • Standard: Frequently used data. The default
  • Standard-IA: Infrequent access: cheaper storage, retrieval fee
  • Glacier classes: Archives: very cheap, slower or costlier to read
  • Intelligent-Tiering: AWS moves objects between tiers for you
  • Lifecycle rules: e.g. logs/ → IA after 30 days, delete after 365

Step 3 · Host a static website

Step three: a static website. Static means plain HTML, CSS, JavaScript and images, with no server-side code. Portfolios, landing pages, documentation, and sites built with tools like Next.js export or Hugo all qualify.

Create a folder with an index dot html, and an error dot html for missing pages.

Upload it with aws s3 sync.

In the bucket's properties tab, scroll to static website hosting, and click edit.

Enable it, and set the index document to index dot html, and the error document to error dot html. Save, and AWS shows you the website endpoint.

Open that address, and you'll get four oh three, forbidden. That's expected, and it's actually good news. The bucket is still private, exactly as we configured it. Next, we decide carefully what to make public.

A quick note on what static hosting can't do. There's no server-side code here, so no PHP, no database queries, and no login handled on the server. For those, you need compute, like the EC2 server from last episode, or containers and serverless functions later in the course. But a surprising number of sites are static, and hosting them this way is cheap, fast, and has almost nothing to hack.

Quick reference

  1. Create a site folder: index.html + error.html
  2. aws s3 sync ./site s3://acme-site-2026
  3. Bucket → Properties → Static website hosting
  4. Enable · Index: index.html · Error: error.html
  5. Open the endpoint → 403 Forbidden. Expected!

website endpoint · example

http://acme-site-2026.s3-website
      .<region>.amazonaws.com

→ 403 Forbidden  (for now)
  the bucket is still private

Step 4 · Allow public reads, only for this site

Step four: allow public reads, but only for this website bucket. In the permissions tab, edit block public access.

Turn it off for this bucket only. Never turn it off for the whole account. Type confirm when AWS asks you to.

Then add a bucket policy. This one allows a single action, get object, for everyone, which is what principal star means, on the objects in this bucket only.

Read it like we learned in episode three: effect allow, action get object, resource every object in acme site. It doesn't allow listing, uploading, or deleting. Just reading files, which is exactly what a website needs.

Reload the website endpoint, and your site is live, with no server to patch, and a tiny storage bill.

Quick reference

  1. Permissions → Block public access → Edit
  2. Turn OFF for this bucket only (not account-wide)
  3. Bucket policy: allow s3:GetObject for everyone
  4. Reload the endpoint → your site is live

bucket policy

{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "PublicReadSite",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource":
      "arn:aws:s3:::acme-site-2026/*"
  }]
}

The professional way: CloudFront in front

What we just built works, and it's great for learning. But for a real website, professionals put CloudFront in front of the bucket. Here's why.

First, HTTPS. The S3 website endpoint only supports plain http, and browsers warn visitors about sites without HTTPS.

Second, speed. CloudFront is AWS's content delivery network. It caches your files in locations around the world, so visitors load the site from somewhere close to them.

Third, the bucket can stay completely private. With origin access control, only CloudFront is allowed to read from the bucket, and nobody can bypass it. You keep block public access turned on.

Fourth, your own domain. AWS Certificate Manager gives you a free certificate, and Route 53, or any DNS provider, points your domain at CloudFront. One detail: for CloudFront, the certificate must be created in the North Virginia region, us east one.

And deploying becomes two commands: sync your files, then create an invalidation, so CloudFront fetches the new versions instead of serving cached old ones.

Quick reference

  • HTTPS: The S3 website endpoint is http only
  • Fast everywhere: CDN caches your site close to visitors
  • Bucket stays private: Origin Access Control: only CloudFront can read
  • Your domain: Free certificate from ACM, DNS in Route 53
  • Deploy = sync + invalidate: aws cloudfront create-invalidation --paths "/*"

S3 mistakes that make the news

S3 is very safe when it's configured well. When it isn't, it makes headlines. Here are the classic mistakes.

Public by accident. Many data leaks you've read about were simply buckets left public. Keep block public access turned on at the account level, and only relax it for specific website buckets, or better, use CloudFront and never relax it at all.

Over-wide policies. A policy with s3 star, meaning every action, or principal star on a bucket that holds private data, is an open door. Always read a policy line by line before you save it.

No versioning. The sync command has a delete option that removes files from the bucket that aren't in your local folder. Run it from the wrong folder, and your site is gone. With versioning, you can recover.

Secrets in buckets. When you sync a whole project folder, it's easy to upload a dot env file or a key along with it. Sync only your build output folder.

And forgotten data. Old buckets that nobody owns keep costing money, and nobody watches their permissions. Tags and lifecycle rules prevent both problems.

Quick reference

  • Public by accident: Keep account-level Block Public Access on
  • Over-wide policies: s3:* or Principal * on a data bucket
  • No versioning: One bad sync --delete wipes your files
  • Secrets in buckets: .env files and keys uploaded with the site
  • Forgotten data: Old buckets nobody owns, still costing money

You can store anything, and host a site

Let's recap. You learned buckets, objects and keys. You created a private, versioned, encrypted bucket. You used the CLI to copy, sync and share files. You learned storage classes and lifecycle rules. And you hosted a static website, and saw why CloudFront is the professional way to serve it.

Clean up when you're done. Because versioning is on, a bucket must be completely empty, including old versions, before you can delete it. In the console, the empty bucket button handles that for you. Then delete the bucket.

In the next episode, we add the last core building block: a database. You'll launch a managed database with RDS, connect to it securely from an EC2 server, and learn backups and high availability. The notes, with the bucket policy and every command, are linked in the description.

Quick reference

Your files → aws s3 sync → S3 bucket → CloudFront

Clean up: empty the bucket (all versions), then delete it

Practice

  1. Add a lifecycle rule that moves objects in logs/ to a cheaper class after 30 days.
  2. Turn on versioning, overwrite a file, then restore the previous version.
  3. Generate a presigned link that expires in 5 minutes, and test it after 6.

Next episode

Episode 6: RDS, running a managed database on AWS.

Key takeaways

  • Bucket names are unique across all of AWS; objects are files identified by a key
  • Keep Block Public Access on, and allow public reads only on purpose, for a website bucket
  • Storage classes and lifecycle rules cut the cost of data you rarely read
  • In production, put CloudFront in front for HTTPS and keep the bucket private