Skip to content
Kuza Ndoto Academy

Hosting a Static Website on S3

Beginner → IntermediateChapter 4 · Page 15 of 304 min readUpdated 15 Nov 2026

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 onlyS3 + CloudFront (recommended)
HTTPSNo, HTTP onlyYes, with a free ACM certificate
BucketMust be publicStays private
Speed for distant usersServed from one RegionCached at edge locations worldwide
Custom domainLimitedYes, 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.)

Browser Route 53 alias record (DNS) 1 DNS lookup CloudFront edge cache + HTTPS 2 HTTPS S3 bucket private, via OAC 3 fetch on cache miss ACM certificate, us-east-1
Figure 1. DNS points the domain at CloudFront. CloudFront serves cached copies from the nearest edge location and only asks the private bucket when it does not have a fresh copy. The certificate for CloudFront must be issued in us-east-1.

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
make_bucket: kuza-portfolio-site-2026 upload: site/index.html to s3://kuza-portfolio-site-2026/index.html upload: site/style.css to s3://kuza-portfolio-site-2026/style.css upload: site/images/me.jpg to s3://kuza-portfolio-site-2026/images/me.jpg

--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

  1. Open CloudFront and choose Create distribution.
  2. Origin: choose your S3 bucket (the bucket's REST endpoint, not a website endpoint).
  3. Origin access: choose Origin access control (OAC) and create a new OAC. This lets only your distribution read the bucket.
  4. Viewer protocol policy: Redirect HTTP to HTTPS.
  5. Default root object: index.html.
  6. 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

  1. 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.
  2. Edit the distribution: add www.example.com as an alternate domain name and select the certificate.
  3. 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 www pointing 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.

Tip

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.

Common mistake

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 sync uploads changes; invalidations refresh CloudFront's cache.
Up next · Storage & DatabasesEBS & EFSBlock and file storage for servers.
→

Tip: use the ← and → keys to move between pages.