Hosting a Static Website on AWS S3: A Detailed Step-by-Step Guide

Hosting a Static Website on AWS S3: A Detailed Step-by-Step Guide

Introduction

In this guide, I'll walk you through the process of hosting a static website using Amazon S3 (Simple Storage Service). By following these steps, you'll learn how to create a public S3 bucket, configure it for web hosting, and make your website accessible to the public.

Step 1: Creating an S3 Bucket

The first step is to open the AWS Management Console and navigate to the S3 service:

  1. Sign in to AWS Console

  2. Click on "Services" and select "S3"

  3. Click the "Create bucket" button

Step 2: Bucket Configuration

When creating your bucket:

  1. Choose a unique bucket name (this must be globally unique across all AWS)

  2. Select your preferred region

  3. Configure the bucket settings:

    • Keep default bucket type (General purpose)

    • Leave ACLs disabled (recommended)

    • Make note of the bucket name for later use

Step 3: Public Access Settings

For a static website, the bucket needs to be publicly accessible:

  1. In the bucket creation page, find "Block Public Access settings"

  2. Uncheck "Block all public access"

  3. Acknowledge the warning about making the bucket public

  4. This step is crucial for your website to be accessible on the internet

Step 4: Enabling Versioning

Bucket versioning helps maintain different versions of your website content:

  1. Still in the bucket creation page

  2. Find the "Bucket Versioning" section

  3. Select "Enable"

  4. This allows you to keep track of all versions of your files

Step 5: Static Website Hosting Configuration

After creating the bucket:

  1. Go to your bucket's Properties tab

  2. Scroll down to "Static website hosting"

  3. Click "Edit"

  4. Select "Enable"

  5. Enter "index.html" as your index document

  6. Optionally, add "error.html" as your error document

  7. Save changes

Step 6: Bucket Policy Configuration

To make your website publicly accessible:

  1. Go to the Permissions tab

  2. Click "Bucket Policy"

  3. Add this policy (replace bucket_name with your actual bucket name):

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

  1. Click "Save changes"

Step 7: Uploading Website Content

Now it's time to upload your website files:

  1. Go to the Objects tab

  2. Click "Upload"

  3. Upload your index.html file

  4. Ensure the file name matches what you specified in the website hosting settings

Step 8: Accessing Your Website

To view your website:

  1. Return to the Properties tab

  2. Scroll down to "Static website hosting"

  3. Find your "Bucket website endpoint"

  4. Click the endpoint URL to view your website

Testing Your Website

Your website should now be live and accessible through the endpoint URL. You should see your index.html content displayed in the browser.

Conclusion

You've successfully hosted a static website using AWS S3! This solution is scalable, cost-effective, and perfect for static content. Remember to:

  • Keep your bucket policy secure

  • Regularly update your content as needed

  • Monitor your AWS costs

  • Consider using CloudFront for better performance