04. Hosting Static Website in S3
Amazon S3 can be used not only for storing data but also for hosting static websites.
A static website typically includes HTML, CSS, JavaScript, and image files β no backend logic or server processing.
When configured properly, S3 serves these files over the internet with a public website endpoint.
π§© Key Conceptsβ
| Concept | Description |
|---|---|
| Static Website Hosting | Enables your S3 bucket to act as a web server for hosting static content. |
| Website Endpoint | A public URL automatically generated by S3 once static hosting is enabled. |
| Index Document | The homepage (e.g., index.html) displayed when users visit the site root. |
| Bucket Policy | Defines public access permissions for your bucketβs content. |
| Public Read Access | Required to make your website visible to everyone on the internet. |
βοΈ Steps to Host a Static Website on S3β
Step 1 β Create an S3 Bucketβ
- Go to the AWS Management Console β S3.
- Click Create bucket.
- Enter a unique bucket name (e.g.,
my-coffee-website). - Choose a region (e.g.,
ap-south-1). - Under Block Public Access settings, uncheck βBlock all public accessβ.
- Confirm acknowledgment β Click Create bucket.
Step 2 β Upload Website Filesβ
- Open your bucket.
- Click Upload β Add files.
- Upload:
index.htmlcoffee.jpgbeach.jpg
- Click Upload.

Step 3 β Enable Static Website Hostingβ
- Go to the Properties tab of your bucket.
- Scroll to Static website hosting β Click Edit.
- Choose Enable.
- Select Host a static website.
- In Index document, enter: index.html
- Click Save changes.

Step 4 β Make Files Publicβ
- Go to the Permissions tab.
- Under Bucket policy, click Edit.
- Add the following JSON policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::himanshupapola-demo-s3-v1/*"
}
]
} - Save the policy.
Step 5 β Access Your Websiteβ
-
Return to the Properties tab.
-
Scroll down to Static website hosting.
-
Copy the Bucket website endpoint (URL).
-
Paste it into your browser.
Example URLs:
http://himanshupapola-demo-s3-v1.s3-website.ap-south-2.amazonaws.com

π§ Troubleshootingβ
| Issue | Cause | Fix |
|---|---|---|
| 403 Forbidden Error | Bucket or objects are not public | Ensure bucket policy allows s3:GetObject for Principal: * |
| Index not loading | Missing index.html file | Upload or rename your homepage file to index.html |
| Image not displaying | Wrong file path or permissions | Verify correct object key and public access |
β Summaryβ
- Amazon S3 can host static websites (HTML, CSS, JS, images).
- Enable Static website hosting under Properties.
- Ensure public read access via a bucket policy.
- Access your site using the S3 website endpoint URL.