Hosting a Static Website on S3
A static website is made of files that are the same for every visitor: HTML, CSS, JavaScript and images, such as a portfolio, a school event page or a React app built to plain files. AWS can host one cheaply and reliably by storing the files in S3 and delivering them worldwide over HTTPS with CloudFront.
Two ways to host
| S3 website endpoint only | S3 + CloudFront (recommended) | |
|---|---|---|
| HTTPS | No, HTTP only | Yes, with a free ACM certificate |
| Bucket | Must be public | Stays private |
| Speed for distant users | Served from one Region | Cached at edge locations worldwide |
| Custom domain | Limited | Yes, with Route 53 or any DNS provider |
The S3 website endpoint is fine for a five-minute experiment, but it needs a public bucket and has no HTTPS. For anything real, use CloudFront in front of a private bucket. (AWS Amplify Hosting is another option that sets this up for you from a Git repository.)
Step 1: Create a private bucket and upload the site
Suppose your site is in a folder called site/ with index.html, style.css and an images/ folder. Create a bucket (leave Block Public Access on) and upload with sync, which copies only changed files. Output is an example:
aws s3 mb s3://kuza-portfolio-site-2026 --region eu-west-1 aws s3 sync ./site s3://kuza-portfolio-site-2026 --delete
--delete removes files from the bucket that no longer exist locally, so the bucket mirrors your folder. Use it carefully.
Step 2: Create a CloudFront distribution
- Open CloudFront and choose Create distribution.
- Origin: choose your S3 bucket (the bucket's REST endpoint, not a website endpoint).
- Origin access: choose Origin access control (OAC) and create a new OAC. This lets only your distribution read the bucket.
- Viewer protocol policy: Redirect HTTP to HTTPS.
- Default root object:
index.html. - Create the distribution, then copy the bucket policy the console offers and paste it into the bucket's Permissions → Bucket policy.
The generated policy looks like this; the distribution ARN is what restricts access to your distribution alone:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontServicePrincipalReadOnly",
"Effect": "Allow",
"Principal": { "Service": "cloudfront.amazonaws.com" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::kuza-portfolio-site-2026/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::123456789012:distribution/E1ABCDEFGHIJKL"
}
}
}
]
}
After a few minutes the distribution is deployed and your site loads at its CloudFront domain, such as https://d111111abcdef8.cloudfront.net.
Step 3: Add your own domain
- In AWS Certificate Manager, switch to the us-east-1 Region (CloudFront only uses certificates from there) and request a public certificate for
www.example.com. Choose DNS validation and create the validation record. - Edit the distribution: add
www.example.comas an alternate domain name and select the certificate. - In Route 53, in your domain's hosted zone, create an A record (and an AAAA record for IPv6) with Alias turned on, pointing to the distribution. If your DNS is managed elsewhere, create a CNAME for
wwwpointing to the CloudFront domain instead.
See Route 53 & CloudFront for more on DNS and caching.
Step 4: Publishing updates
CloudFront caches files at the edge, so after uploading new versions, visitors may see old copies until the cache expires. Ask CloudFront to fetch fresh copies with an invalidation:
aws s3 sync ./site s3://kuza-portfolio-site-2026 --delete aws cloudfront create-invalidation --distribution-id E1ABCDEFGHIJKL --paths "/*"
A common alternative is to give CSS and JavaScript files versioned names (such as app.3f9a1c.js, which build tools do automatically), so only index.html ever needs invalidating.
Single-page apps (React, Vue) handle routes like /about in the browser. Configure CloudFront custom error responses so that 403 and 404 errors return /index.html with status 200, or deep links will fail.
Costs and clean-up
You pay for S3 storage and requests, CloudFront data transfer and requests, and a monthly fee for each Route 53 hosted zone (domain registration is extra). For a small personal site these are usually low, but check the pricing pages. To remove the site: disable and then delete the distribution, empty and delete the bucket, and delete the hosted zone and DNS records if you no longer need them.
Making the bucket public "because CloudFront showed Access Denied". The usual causes are a missing bucket policy for the OAC, no default root object, or requesting a file whose key does not match (keys are case-sensitive). Fix the cause; keep the bucket private.
Key points
- Host static files in a private S3 bucket and serve them through CloudFront.
- Origin access control lets only your distribution read the bucket.
- Use a free ACM certificate from us-east-1 for HTTPS on a custom domain, and a Route 53 alias record to point the domain at CloudFront.
aws s3 syncuploads changes; invalidations refresh CloudFront's cache.
Tip: use the ← and → keys to move between pages.
