AWS Builder Center

Why S3 "Static Website Hosting" Is a Trap for Modern Frontends

Why enabling S3's built-in website endpoint breaks modern SPAs and forces your bucket public, and how to set it up properly with CloudFront.

When I was first wrapping my head around how Amazon S3 serves static websites, the thing that made it click was realizing how simple static hosting actually is. At the end of the day, a static web server just takes an HTTP  GET  request, reads a file, and sends the bytes back with a  Content-Type: text/html  header.
By default, S3 isn't a web server—it's a key-value object store with a REST API. It doesn't even have real folders, just flat keys with  /  characters in their names. If you ask the standard S3 API for  /about/ , it has no idea you actually want  /about/index.html .
When you go into your bucket properties and enable Static Website Hosting, AWS gives you a completely different URL ( s3-website-<region>.amazonaws.com ). That endpoint is basically a stripped-down web server sitting in front of your bucket. It knows a couple of classic web server tricks: if someone requests  / , it automatically fetches the  index.html  key, and if a key doesn't exist, it serves your custom error file.
It’s great for a quick test, but if you're deploying a real frontend, turning that toggle on sets you up for three annoying problems.
1. The website endpoint doesn't support HTTPS While the standard S3 REST API supports HTTPS, the  s3-website  endpoint only speaks plain HTTP. If you want to use a custom domain with an SSL/TLS certificate, S3 Static Website Hosting simply cannot do it on its own.
2. You have to make your bucket public To let browsers read your HTML, CSS, and JS through the website endpoint, you have to turn off "Block all public access" and write a public read bucket policy. Opening up a bucket to the public internet is a bad habit to get into, and in most production AWS environments, account-level security policies will block you from doing it anyway.
3. The Single Page App (SPA) refresh bug If you upload a React or Vue build to S3, clicking around your app works fine at first because the browser's History API updates the URL locally via JavaScript without talking to the server.
The second you hit F5 on a route like  /dashboard , the browser makes a real HTTP  GET  request to S3 asking for an object named  dashboard . S3 checks its index for that exact key, doesn't find it, and throws a  404 Not Found .
On a normal server like Nginx, you fix this with one line:  try_files $uri /index.html; . In S3, the common hack is setting  index.html  as the bucket's "Error document." Your page renders, sure, but S3 still returns a hard HTTP  404  status code in the network tab for every valid route in your app.
The actual fix: Turn off Website Hosting and use CloudFront
Counterintuitively, the best way to host a static site on S3 is to leave Static Website Hosting disabled.
Instead of exposing the bucket as a web server, keep the S3 bucket 100% private and put an Amazon CloudFront distribution in front of the standard S3 REST API:
  • Private bucket: You connect CloudFront to S3 using Origin Access Control (OAC). Users hit CloudFront, and only CloudFront has IAM permission to read objects from your bucket.
  • Free HTTPS and edge caching: CloudFront lets you attach a free SSL certificate from AWS Certificate Manager (ACM) and caches your assets at edge locations instead of hitting a single S3 region on every request.
  • Clean SPA routing: When a user refreshes  /dashboard , S3 tells CloudFront the object doesn't exist ( 403 Forbidden  on private buckets). You can configure CloudFront's Custom Error Responses to catch that  403 , return  /index.html  to the browser, and rewrite the HTTP status code to  200 OK .
S3's website toggle is a cool way to see how object storage can mimic a basic HTTP server, but for anything beyond a quick experiment, letting CloudFront handle the web layer saves a lot of headaches.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article