Overview
Amazon S3 (Simple Storage Service) can serve static websites directly from a bucket. This project walks you through uploading your HTML, CSS, and JavaScript files to S3 and configuring the bucket to make them publicly accessible via a URL.
What You Will Learn
- Creating and configuring an S3 bucket
- Uploading static files to S3
- Setting bucket policies for public read access
- Enabling static website hosting on an S3 bucket
- Understanding S3 URL structure
Prerequisites
- An AWS account (free tier is sufficient)
- Basic knowledge of HTML
- AWS CLI installed (optional but recommended)
Architecture
User Browser → S3 Static Website Endpoint → S3 Bucket (index.html, styles.css, ...)
Steps
1. Create an S3 Bucket
- Sign in to the AWS Console.
- Navigate to S3 and click Create bucket.
- Choose a globally unique bucket name (e.g.,
my-static-site-2024). - Select the AWS region closest to your users.
- Uncheck “Block all public access” — we need public access for a website.
- Acknowledge the warning and click Create bucket.
2. Upload Your Website Files
- Open the bucket you just created.
- Click Upload and add your
index.html, CSS, JavaScript, and any asset files. - Click Upload to confirm.
A minimal index.html to get started:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My S3 Website</title>
</head>
<body>
<h1>Hello from S3!</h1>
</body>
</html>
3. Enable Static Website Hosting
- Go to your bucket → Properties tab.
- Scroll to Static website hosting and click Edit.
- Select Enable.
- Set Index document to
index.html. - Optionally set Error document to
error.html. - Save changes.
Note the Bucket website endpoint URL shown — this is your site’s address.
4. Set a Bucket Policy for Public Read
- Go to Permissions tab → Bucket policy → Edit.
- Paste the following policy (replace
YOUR-BUCKET-NAME):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"
}
]
}
- Save the policy.
5. Access Your Website
Open the Bucket website endpoint URL from Step 3 in your browser. You should see your index.html rendered.
Clean Up
To avoid any charges, delete the bucket when you are done:
- Empty the bucket (delete all objects).
- Delete the bucket from the S3 console.
Going Further
- Add a custom domain using Route 53.
- Put CloudFront in front of S3 for HTTPS and caching.
- Automate deployments with GitHub Actions and the AWS CLI.