How to Publish a Static Website on S3

This article provides step-by-step instructions on how to host a static website using Amazon S3.

Prerequisites

Step 1: Create an S3 Bucket

  1. Go to the S3 console: https://s3.console.aws.amazon.com/s3/
  2. Click 'Create bucket'.
  3. Name your bucket the same as your domain (e.g., example.com).
  4. Choose a region.
  5. Uncheck 'Block all public access' (you'll set permissions manually).
  6. Leave the rest as default and click 'Create bucket'.

Step 2: Enable Static Website Hosting

  1. Go to the bucket's 'Properties' tab.
  2. Scroll to 'Static website hosting' and click 'Edit'.
  3. Enable static website hosting.
  4. Enter index.html as the index document.
  5. Optionally enter error.html as the error document.
  6. Save changes.

Step 3: Upload Your Website Files

  1. Go to the 'Objects' tab.
  2. Click 'Upload'.
  3. Upload all your HTML, CSS, JS, and asset files.
  4. Click 'Upload' to complete.

Step 4: Make Files Public

  1. Go to the bucket's 'Permissions' tab.
  2. Scroll to 'Bucket policy' and add the following (replace BUCKET_NAME):
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::BUCKET_NAME/*"
    }
  ]
}
  1. Save the policy.

Step 5: Access Your Website

  1. Go to the bucket's 'Properties' tab.
  2. Scroll to 'Static website hosting'.
  3. Copy the Endpoint URL (e.g., http://example.com.s3-website-us-east-1.amazonaws.com).
  4. Paste it in your browser to see your live site.

Notes