Static website hosting
Serving a static website from an S3 bucket, the website endpoint URLs, the 403 error, and why HTTPS needs CloudFront.
What it is
A static website is made of files that don't change per visitor: HTML, CSS, JavaScript and images. S3 can serve such a site directly from a bucket and make it reachable on the internet, with no web server to run. (Pages built on a server per request, such as PHP, need EC2, containers or Lambda instead.)
How it works
- Static website hosting is turned on for the bucket, naming an index document (
index.html) and optionally an error document (error.html). - S3 gives the bucket a website endpoint. Depending on the Region, it looks like either:
http://bucket-name.s3-website-aws-region.amazonaws.com, orhttp://bucket-name.s3-website.aws-region.amazonaws.com.
- Visitors' browsers request pages from that endpoint, and S3 returns the files.
For this to work, the objects must be publicly readable: turn off Block Public Access for the bucket and add a bucket policy that allows s3:GetObject to everyone.
If a 403 Forbidden error appears, the bucket policy doesn't allow public reads (or Block Public Access is still on).
HTTPS and custom domains
- Website endpoints only speak HTTP. They don't support HTTPS.
- For HTTPS, put Amazon CloudFront in front of the bucket (see CloudFront). CloudFront can also keep the bucket private, using origin access control, so public access isn't needed at all. AWS also suggests AWS Amplify Hosting for simple sites.
- A bucket encrypted with SSE-KMS can't serve anonymous visitors through the website endpoint; use CloudFront.
- For a custom domain name (
www.example.com), use Route 53 with CloudFront, or a bucket named exactly like the domain.
Real-world examples
- A product launch page is a few HTML files and images in a bucket. It costs pennies and survives any traffic spike.
- A single-page app (React, Vue) is built into static files, stored in S3 and served worldwide over HTTPS through CloudFront.
Exam tips
- "Host a static website cheaply with no servers" → S3 static website hosting.
- "403 Forbidden on the S3 website" → add a bucket policy allowing public
s3:GetObject(and turn off Block Public Access). - "Static website with HTTPS" → CloudFront in front of S3.
- "Website with server-side code" → not S3 alone; use compute.
Common traps
- "Enable HTTPS on the S3 website endpoint." Not supported; use CloudFront.
- "Static website hosting makes objects public." The bucket policy is still needed.
Hands-on lab: a website in a bucket
Goal: host a one-page website from S3.
Costs money
A few small files and requests cost less than a cent. Any Region works.
Create the bucket and files
Create a bucket saa-site-<random> in us-east-1 with tag Project=saa-lab. On your computer, create index.html containing <h1>Hello from S3</h1> and error.html containing <h1>Not found</h1>. Upload both.
Turn on website hosting
Bucket → Properties → Static website hosting → Edit → Enable. Index document index.html, error document error.html. Save, and copy the Bucket website endpoint at the bottom of Properties.
Open it, see 403, then fix it
Open the endpoint: 403 Forbidden. Now Permissions → Block public access → Edit, untick everything, confirm. Add a bucket policy allowing s3:GetObject on arn:aws:s3:::saa-site-<random>/* to "Principal": "*" (as on the bucket policies page). Reload: "Hello from S3". Try /missing.html: your error page.
Expected result: a public website served over HTTP from your bucket's website endpoint.
Clean up: empty and delete the saa-site-<random> bucket.
AWS documentation
Security and bucket policies
How access to S3 is decided, IAM policies vs bucket policies vs ACLs, bucket policy examples, and Block Public Access.
Versioning and replication
S3 versioning, delete markers and suspending versioning, then Cross-Region and Same-Region Replication, Batch Replication, delete markers and why replication doesn't chain.