How to Host a Static Website Using Amazon S3

Table of Contents

Amazon S3 (Simple Storage Service) lets you host static websites. Static websites are made up of HTML, CSS, JavaScript, and media files — no server-side code is needed.

This guide will walk you through the steps to set up and publish a static website using an S3 bucket.


Step 1: Create an S3 Bucket

  1. Go to the S3 Console in AWS.
  2. Click Create bucket.
  3. Enter a unique name for your bucket. For website hosting, the bucket name should match your domain name (e.g., example.com).
  4. Choose a region.
  5. Uncheck Block all public access (you'll make the bucket public for web access).
  6. Acknowledge the warning and click Create bucket.

Step 2: Upload Your Website Files

  1. Open your new bucket.
  2. Click Upload.
  3. Add your HTML, CSS, JS, and other static files.
  4. Click Upload.

Step 3: Set Permissions to Make Files Public

You need to make your files publicly readable:

  1. Go to the Permissions tab.
  2. Scroll to Bucket Policy.
  3. Add a policy like this:

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

Replace your-bucket-name with the actual name of your bucket.


Step 4: Enable Static Website Hosting

  1. Go to the Properties tab of the bucket.
  2. Scroll to Static website hosting.
  3. Click Edit.
  4. Choose Enable.
  5. Enter the name of your index document (e.g., index.html). You can also add an error document (e.g., error.html).
  6. Save changes.

After saving, you'll see a Bucket website endpoint. This is the URL of your website.


Step 5: (Optional) Use a Custom Domain with Route 53

If you have a domain name, you can use Amazon Route 53 to point it to your S3 site:

  1. Create a hosted zone for your domain.
  2. Add an Alias record pointing to the S3 website endpoint.

Make sure your S3 bucket name matches your domain exactly (e.g., example.com) for this to work.


Summary

Hosting a static website with Amazon S3 is simple and doesn't require a server. You just upload your files, set public access, and turn on website hosting. You can also link a custom domain if you have one.

Let me know if you need help with custom error pages or adding HTTPS using CloudFront.