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
- Go to the S3 Console in AWS.
- Click Create bucket.
- Enter a unique name for your bucket. For website hosting, the bucket name should match your domain name (e.g.,
example.com
). - Choose a region.
- Uncheck Block all public access (you'll make the bucket public for web access).
- Acknowledge the warning and click Create bucket.
Step 2: Upload Your Website Files
- Open your new bucket.
- Click Upload.
- Add your HTML, CSS, JS, and other static files.
- Click Upload.
Step 3: Set Permissions to Make Files Public
You need to make your files publicly readable:
- Go to the Permissions tab.
- Scroll to Bucket Policy.
- 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
- Go to the Properties tab of the bucket.
- Scroll to Static website hosting.
- Click Edit.
- Choose Enable.
- Enter the name of your index document (e.g.,
index.html
). You can also add an error document (e.g.,error.html
). - 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:
- Create a hosted zone for your domain.
- 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.