How to Host a Static Website on Amazon S3
- EN
- PT
Table of Contents
Learn how to host your static website on Amazon S3 quickly and cost-effectively.
#
Introduction
Amazon S3 (Simple Storage Service) is an excellent option for hosting static websites. It’s cost-effective, scalable, and easy to configure. In this guide, you’ll learn how to set up static website hosting on S3.
#
What You’ll Need
- AWS account
- Static website (HTML, CSS, JS files)
- Domain name (optional)
#
Step-by-Step Guide
##
1. Create an S3 Bucket
- Access the AWS Console
- Navigate to S3 service
- Click “Create bucket”
- Choose a unique name for your bucket
- Select your preferred region
- Uncheck “Block all public access”
- Click “Create bucket”
##
2. Upload Your Website Files
- Open your created bucket
- Click “Upload”
- Add your website files
- Make sure you have an
index.html
file
##
3. Configure Static Website Hosting
- In your bucket, go to “Properties” tab
- Scroll down to “Static website hosting”
- Click “Edit”
- Select “Enable”
- Set index document:
index.html
- Set error document:
error.html
(optional) - Save changes
##
4. Configure Bucket Policy
Add this policy to make your files publicly readable:
{
"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 your actual bucket name.
##
5. Access Your Website
Your website will be available at:
http://YOUR-BUCKET-NAME.s3-website-REGION.amazonaws.com
#
Adding a Custom Domain
To use your own domain:
- Configure Route 53 or your DNS provider
- Create a CNAME record pointing to your S3 endpoint
- Consider using CloudFront for HTTPS and better performance
#
Benefits of S3 Hosting
- Low cost: Pay only for storage and bandwidth used
- High availability: 99.999999999% (11 9’s) durability
- Scalability: Handles traffic spikes automatically
- Easy deployment: Simple file upload process
#
Limitations
- Only supports static content
- No server-side processing
- Limited to HTTP (HTTPS requires CloudFront)
#
Conclusion
Amazon S3 is an excellent choice for hosting static websites. It’s simple to set up, cost-effective, and highly reliable. For more advanced features like HTTPS and CDN, consider adding CloudFront to your setup.
Need help with AWS or web development? Feel free to contact me!