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
- An AWS account
-
An HTML/CSS/JS website project (
index.html
is required)
Step 1: Create an S3 Bucket
-
Go to the S3 console:
https://s3.console.aws.amazon.com/s3/
- Click 'Create bucket'.
-
Name your bucket the same as your domain (e.g.,
example.com
).
- Choose a region.
-
Uncheck 'Block all public access' (you'll set permissions manually).
- Leave the rest as default and click 'Create bucket'.
Step 2: Enable Static Website Hosting
- Go to the bucket's 'Properties' tab.
- Scroll to 'Static website hosting' and click 'Edit'.
- Enable static website hosting.
- Enter
index.html
as the index document.
- Optionally enter
error.html
as the error document.
- Save changes.
Step 3: Upload Your Website Files
- Go to the 'Objects' tab.
- Click 'Upload'.
- Upload all your HTML, CSS, JS, and asset files.
- Click 'Upload' to complete.
Step 4: Make Files Public
- Go to the bucket's 'Permissions' tab.
-
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/*"
}
]
}
- Save the policy.
Step 5: Access Your Website
- Go to the bucket's 'Properties' tab.
- Scroll to 'Static website hosting'.
-
Copy the Endpoint URL (e.g.,
http://example.com.s3-website-us-east-1.amazonaws.com
).
- Paste it in your browser to see your live site.
Notes
-
AWS S3 hosting is suitable for static websites only (no server-side
code).
-
For HTTPS or custom domain support, consider using Route 53 and
CloudFront.