Skip to main content

João Senger

How to Host a Static Website on Amazon S3

Table of Contents

Learn how to host your static website on Amazon S3 quickly and cost-effectively.

# Introduction

Amazon S3 (Simple Storage Service) is an excellent option for hosting static websites. It’s cost-effective, scalable, and easy to configure. In this guide, you’ll learn how to set up static website hosting on S3.

# What You’ll Need

  • AWS account
  • Static website (HTML, CSS, JS files)
  • Domain name (optional)

# Step-by-Step Guide

## 1. Create an S3 Bucket

  1. Access the AWS Console
  2. Navigate to S3 service
  3. Click “Create bucket”
  4. Choose a unique name for your bucket
  5. Select your preferred region
  6. Uncheck “Block all public access”
  7. Click “Create bucket”

## 2. Upload Your Website Files

  1. Open your created bucket
  2. Click “Upload”
  3. Add your website files
  4. Make sure you have an index.html file

## 3. Configure Static Website Hosting

  1. In your bucket, go to “Properties” tab
  2. Scroll down to “Static website hosting”
  3. Click “Edit”
  4. Select “Enable”
  5. Set index document: index.html
  6. Set error document: error.html (optional)
  7. Save changes

## 4. Configure Bucket Policy

Add this policy to make your files publicly readable:

{
    "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 your actual bucket name.

## 5. Access Your Website

Your website will be available at:

http://YOUR-BUCKET-NAME.s3-website-REGION.amazonaws.com

# Adding a Custom Domain

To use your own domain:

  1. Configure Route 53 or your DNS provider
  2. Create a CNAME record pointing to your S3 endpoint
  3. Consider using CloudFront for HTTPS and better performance

# Benefits of S3 Hosting

  • Low cost: Pay only for storage and bandwidth used
  • High availability: 99.999999999% (11 9’s) durability
  • Scalability: Handles traffic spikes automatically
  • Easy deployment: Simple file upload process

# Limitations

  • Only supports static content
  • No server-side processing
  • Limited to HTTP (HTTPS requires CloudFront)

# Conclusion

Amazon S3 is an excellent choice for hosting static websites. It’s simple to set up, cost-effective, and highly reliable. For more advanced features like HTTPS and CDN, consider adding CloudFront to your setup.


Need help with AWS or web development? Feel free to contact me!