Amazon Simple Storage Service (S3) is a highly scalable, durable, and secure object storage service offered by AWS. One of its popular use cases is hosting static websites — websites that consist of HTML, CSS, JavaScript, and media files without server-side processing.
In this blog post, I’ll guide you step-by-step on how to set up and host your static website using Amazon S3.
Why Use S3 for Static Website Hosting?
- Cost-effective: You pay only for the storage and bandwidth you use.
- Scalable: Handles any traffic without needing server management.
- High availability: Designed for 99.999999999% durability.
- Easy integration: Works seamlessly with other AWS services like CloudFront.
Step 1: Create an S3 Bucket
- Log in to the AWS Management Console.
- Navigate to the S3 service.
- Click Create bucket.
- Enter a unique bucket name (e.g.,
my-static-site-bucket
). - Choose the region closest to your audience.
- Leave other settings default or customize as needed.
- Click Create bucket.
Step 2: Upload Your Website Files
- Upload your static files (index.html, styles.css, images, etc.) to your new bucket.
Step 3: Configure the Bucket for Website Hosting
- Select your bucket.
- Go to the Properties tab.
- Click on Static website hosting.
- Enable Use this bucket to host a website.
- Enter
index.html
as the Index document. - Optionally, add an Error document (e.g.,
error.html
). - Save changes.
Step 4: Set Bucket Policy for Public Access
To make your website accessible to everyone, you need to update the bucket policy:
- Go to the Permissions tab.
- Click Bucket Policy.
- Add this JSON policy (replace
YOUR_BUCKET_NAME
):
jsonCopyEdit{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadGetObject",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::YOUR_BUCKET_NAME/*"]
}]
}
- Save the policy.
Step 5: Access Your Website
- Your website is now available at the endpoint provided in the Static website hosting section, usually:
cppCopyEdithttp://YOUR_BUCKET_NAME.s3-website-REGION.amazonaws.com
Conclusion
Hosting a static website on Amazon S3 is simple, reliable, and cost-effective. Whether you’re hosting a personal portfolio, blog, or project documentation, S3 can handle it with minimal setup.
If you want to improve performance, you can integrate your S3 website with Amazon CloudFront for CDN and HTTPS support.