DEV Community

Cover image for How to Deploy a Static Website with S3 and CloudFront on AWS
Oluwatobi
Oluwatobi

Posted on

How to Deploy a Static Website with S3 and CloudFront on AWS

Want to host a fast, secure, and globally distributed website with no backend server?

In this hands-on guide, I’ll walk you through how to host a static website using Amazon S3 and CloudFront — perfect for portfolios, documentation, or product landing pages.


What You’ll Need

  • ✅ An AWS Account (free tier works)
  • ✅ A static website (HTML, CSS, JS files)
  • ✅ Optional: Custom domain + SSL

Step-by-Step Guide

🔹 Step 1: Create an S3 Bucket

  • Go to S3 in AWS Console.

Image description

  • Click "Create Bucket"

Image description

  • Name it exactly as your domain name (e.g. mywebsite.com)

Image description

  • Uncheck Block all public access ✅ (you’ll change permissions later)

Image description

  • Create Bucket > click on the created bucket >

Image description

  • Enable static website hosting:
  • Under "Properties" > Static Website Hosting

Image description

  • Select: Enable

Image description

Image description

  • Enter your index.html and error.html file names

Image description


🔹 Step 2: Upload Your Website Files

  • Upload your index.html, styles.css, and other static files into the bucket.

Image description

Image description


🔹 Step 3: Set Bucket Policy for Public Read

Image description

  • Go to Permissions > Bucket Policy

Image description

and paste this (update your bucket name):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::your-bucket-name/*"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

🔹 Step 4: Set Up CloudFront

  • Go to CloudFront > Create Distribution

Image description

  • Under Origin domain, choose your S3 bucket

Image description

  • Set Viewer Protocol Policy to Redirect HTTP to HTTPS

Image description

  • Enable Custom Error Responses (optional)
  • Leave other defaults or fine-tune caching rules

Image description

🔹 Step 5: Connect a Custom Domain (Optional)
If you have a domain (from Route 53 or elsewhere):

Add an alternate domain name (CNAME) to CloudFront

Use AWS Certificate Manager (ACM) to create an SSL cert

Update your DNS settings to point to the CloudFront distribution

💡 Bonus Tips
✅ Enable versioning in S3 for rollbacks

✅ Use CloudFront invalidation to force-refresh cache

✅ Add security headers with Lambda@Edge (advanced)

🎉 Done! Your Static Site is Live on AWS
You now have a fast, global, scalable site hosted with S3 and accelerated by CloudFront.

Top comments (0)