Hosting a Static Website on AWS S3
Create a bucket, allow public reads, enable website hosting and deploy a build with one CLI command.
- aws
- s3
- static-hosting
- react
- deployment
On this page · 14 sections
Static hosting is the simplest way to put a website on the internet: no server to patch, no process to restart, and costs that stay low until traffic grows. Amazon S3 can serve a static site directly from a bucket. This guide takes a built React (or any static) site from npm run build to a live S3 website endpoint, and explains the permission settings that cause most of the confusion.
What "static website hosting" means on S3
S3 normally serves objects through an API that requires signed requests. Static website hosting is a bucket feature that exposes a public HTTP endpoint which behaves like a basic web server: it serves an index document for directory requests and an error document when an object is missing.
It is a good fit for:
- Single-page apps built with React, Vue or Svelte
- Documentation and marketing sites from static generators
- Next.js projects that can be exported to static HTML
It is not a fit for server-rendered apps. A standard Next.js app that uses server-side rendering, route handlers or middleware needs a server runtime, so hosting it on S3 alone will not work.
Prerequisites
- An AWS account and the AWS CLI configured with
aws configure - A project that builds to a folder of static files (
dist/for Vite,build/for Create React App,out/for a Next.js static export)
Step 1: Build the site
npm cinpm run buildls dist # index.html, assets/...If your site is a single-page app, check that routing is client-side. The router will handle /dashboard in the browser, but S3 has no /dashboard object. You will handle that with the error document in Step 5.
Step 2: Create the bucket
Bucket names are globally unique across all AWS accounts, lowercase, and 3–63 characters. Choose the region closest to your users (or to you, if you only need a demo).
export BUCKET=my-portfolio-site-2026export REGION=us-east-1aws s3api create-bucket --bucket "$BUCKET" --region "$REGION"For any region other than us-east-1, add a location constraint:
aws s3api create-bucket --bucket "$BUCKET" --region eu-west-1 \ --create-bucket-configuration LocationConstraint=eu-west-1Step 3: Allow public reads (and why it is blocked by default)
New buckets have Block Public Access enabled on purpose. That is the right default for almost everything, but a public website has to be public. Turn off only the settings that block bucket policies for this bucket:
aws s3api put-public-access-block --bucket "$BUCKET" \ --public-access-block-configuration \ BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=false,RestrictPublicBuckets=falseThis keeps ACL-based public access blocked while allowing a public bucket policy. Now add a policy that allows anyone to read objects, and nothing else:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadForWebsite", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::my-portfolio-site-2026/*" } ]}aws s3api put-bucket-policy --bucket "$BUCKET" --policy file://policy.jsonNotice what is not granted: no s3:ListBucket, no write access. Visitors can fetch known files but cannot list or modify the bucket.
Step 4: Enable static website hosting
aws s3 website "s3://$BUCKET/" --index-document index.html --error-document index.htmlThe index document is returned for requests to a folder (/). The error document is returned with an error status when an object is missing.
For a single-page app, using index.html as the error document makes client-side routes work: a request for /dashboard misses, S3 returns index.html, and your router renders the right view. One caveat: S3 returns that page with a 404 status, which is fine for users but not ideal for SEO. If SEO matters for deep routes, pre-render them (static export) or serve through CloudFront, where you can return a 200 for those paths.
Step 5: Upload the build
aws s3 sync uploads only what changed. Setting cache headers per file type makes a big difference:
# Fingerprinted assets can be cached for a yearaws s3 sync dist "s3://$BUCKET" --delete \ --exclude "index.html" \ --cache-control "public,max-age=31536000,immutable"# index.html must always be revalidated so new deploys show upaws s3 cp dist/index.html "s3://$BUCKET/index.html" \ --cache-control "no-cache" --content-type "text/html"Bundlers like Vite and webpack put a content hash in asset filenames (app.3f9c1a.js), which is why they can be cached "forever". index.html references those names, so it must not be cached aggressively.
Step 6: Find and test the website endpoint
The website endpoint follows this pattern (the separator differs between regions, so copy it from the console under Properties → Static website hosting):
http://my-portfolio-site-2026.s3-website-us-east-1.amazonaws.comcurl -I "http://$BUCKET.s3-website-$REGION.amazonaws.com"You should see 200 OK and Content-Type: text/html. Then open it in a browser and test a deep link such as /about to confirm single-page routing.
Deploying a Next.js static export
Next.js can produce a fully static site when the app does not need a server at request time:
// next.config.tsimport type { NextConfig } from "next";const nextConfig: NextConfig = { output: "export", images: { unoptimized: true }, // the default image optimizer needs a server trailingSlash: true, // /about/ -> about/index.html, which S3 resolves cleanly};export default nextConfig;next build then writes the site to out/. Upload that folder exactly as in Step 5. Remember the limits: no server-side rendering, no route handlers, no middleware and no incremental static regeneration. If your app needs those, deploy a Node runtime (EC2, containers or a platform that supports it) instead.
Security considerations
- Only grant
s3:GetObjectpublicly. Never make the whole bucket writable or listable. - Keep a separate deploy identity. Use an IAM user or role limited to this bucket, not your admin credentials:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:ListBucket"], "Resource": "arn:aws:s3:::my-portfolio-site-2026" }, { "Effect": "Allow", "Action": ["s3:PutObject", "s3:DeleteObject"], "Resource": "arn:aws:s3:::my-portfolio-site-2026/*" } ]}- Do not put secrets in the build. Everything in a static site is public, including environment variables inlined at build time.
- The S3 website endpoint is HTTP only. Use CloudFront for HTTPS, security headers and a custom domain.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
403 Forbidden | Missing public-read policy or Block Public Access still on | Re-check Step 3 |
404 Not Found on / | Index document not set | Set index.html in website settings |
| 404 on deep link in an SPA | No error document | Set error document to index.html |
| Old content after deploy | Browser or CDN cache | no-cache on index.html, invalidate CDN |
| Wrong content type (downloads instead of rendering) | Metadata not set on upload | Re-upload with correct --content-type |
NoSuchBucket | Bucket name or region mismatch | Verify the endpoint matches the bucket's region |
Validating a deployment
After a deploy, check that the page loads, that a deep link works, that the browser cache headers are what you expect and that the old files are gone:
curl -I "http://$BUCKET.s3-website-$REGION.amazonaws.com/"curl -I "http://$BUCKET.s3-website-$REGION.amazonaws.com/assets/app.3f9c1a.js"aws s3 ls "s3://$BUCKET" --recursive | headBest practices
- Put CloudFront in front for HTTPS, caching and a custom domain.
- Deploy from CI with a least-privilege role rather than from your laptop.
- Use fingerprinted asset names and long cache lifetimes; keep
index.htmluncached. - Enable bucket versioning if you want an easy rollback path.
- Keep one bucket per environment (staging and production).
Conclusion
S3 static hosting is mostly a matter of getting four things right: a unique bucket, a narrowly scoped public-read policy, the index and error documents, and sensible cache headers on upload. The result is a site with almost no operational burden. The natural next step is adding CloudFront, which gives you HTTPS, a custom domain and global caching while letting you keep the bucket private.
Frequently asked questions
+Can I host a React or Vue app on S3?
Yes, as long as it builds to static files (HTML, CSS, JavaScript and assets). A single-page app needs the error document set to index.html so client-side routes like /dashboard load instead of returning an error.
+Why do I get 403 Access Denied on my S3 website?
Almost always one of three things: Block Public Access is still on, there is no bucket policy allowing s3:GetObject, or the objects are owned by another account with restrictive ACLs. Fix the bucket policy and Block Public Access settings first.
+Does S3 static website hosting support HTTPS?
The S3 website endpoint only serves HTTP. To get HTTPS and a custom domain, put CloudFront in front of the bucket, which also gives you caching and lower latency.
+Can I host a Next.js app on S3?
Only if it can be exported to static files with output: 'export'. Features that need a server at request time (server-side rendering, route handlers, middleware, ISR, default image optimization) are not available in a static export.
+How much does S3 static hosting cost?
You pay for storage, requests and data transfer out. For a small site the total is usually very small, but check the current S3 pricing page for your region because rates change.
+How do I redeploy after changing my site?
Rebuild, then run aws s3 sync with the --delete flag to upload changes and remove stale files. If CloudFront is in front, create an invalidation so edge caches refresh.
+Should the bucket name match my domain?
For direct S3 website hosting with a custom domain through Route 53 alias records, yes, the bucket name must match the domain. With CloudFront in front, the bucket name no longer matters.