This project demonstrates how to host a static website using AWS S3 and AWS Amplify services. This approach provides a scalable, cost-effective solution for deploying static web applications with enhanced features like custom domains and SSL certificates.
- π High Performance - Global content delivery through AWS infrastructure
- π° Cost-Effective - Pay only for what you use
- π Secure - Built-in SSL/TLS encryption
- π Custom Domains - Easy domain management and configuration
- π Scalable - Automatically handles traffic spikes
- π‘οΈ WAF Integration - Web Application Firewall protection available
- AWS S3 (Simple Storage Service)
- AWS Amplify
- HTML/CSS/JavaScript
- Custom Domain Management
- Web Application Firewall (WAF)
Before starting this project, ensure you have:
- An active AWS account
- Basic understanding of AWS services
- A static website (HTML, CSS, JS files)
- Optional: A custom domain name
-
Download the project code from GitHub
Navigate to the repository and download the code as a ZIP file to your local machine:
# Repository URL https://github.com/AbhayGhante/aws-static-web-hosting
-
Alternatively, you can clone the repository:
git clone https://github.com/AbhayGhante/aws-static-web-hosting.git
Navigate to the S3 dashboard in your AWS Console and create a new S3 bucket:
- Click on "Create bucket"
- Provide a globally unique name for your S3 bucket
- Select your preferred AWS region
- Click "Create bucket"
# Example bucket naming convention
bucket-name: your-project-name-static-website-2025Upload all your website files to the newly created S3 bucket:
- Click on the "Upload" button
- Select all files from your downloaded/cloned project
- Ensure all HTML, CSS, JS, and asset files are uploaded
- Click "Upload" to complete the process
# Typical file structure
βββ index.html
βββ 404.html
βββ css/
β βββ styles.css
βββ js/
β βββ script.js
βββ assets/
βββ images/Configure your S3 bucket for static website hosting:
- Navigate to Properties tab
- Scroll down to "Static website hosting"
- Click "Edit"
- Enable static website hosting
- Set Index document:
index.html - Set Error document:
404.html - Save changes
Modify bucket permissions to allow public access:
- Go to Permissions tab
- Edit "Block public access settings"
- Uncheck all blocking options to allow public access
- Save changes
- Add a bucket policy for public read access:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}Your S3 bucket is now configured for static website hosting. You should have a working website URL provided by S3.
AWS recommends using AWS Amplify for hosting static websites as it provides additional features such as:
- Custom domain management
- SSL/TLS certificates
- WAF (Web Application Firewall) integration
- CI/CD capabilities
Navigate to the AWS Amplify dashboard:
- Click on "Create new app"
- Choose your deployment method
Step 1: Choose Create Method
- Select "Deploy without Git" for manual deployment
Step 2: Start Manual Deployment
- Provide a descriptive name for your application
- Select "Amazon S3" as the deployment method
- Browse and select the S3 bucket created in previous steps
- Click "Save and Deploy"
# Application naming example
App name: aws-static-website-hosting-demo
Environment: stagingIf you have a custom domain, you can configure it:
- Click on "Add domain" in your Amplify app dashboard
- This step is optional but recommended for production websites
Enter your domain configuration:
- Input your custom domain name
- Click "Configure domain"
- Choose SSL certificate option:
- Amplify managed certificate (recommended for most users)
- Custom SSL certificate (if you have your own)
- Click "Add domain" to complete the setup
# Domain configuration example
Domain: yourdomain.com
Subdomain: www (optional)
SSL: Amplify managed certificateFor additional security, enable Web Application Firewall:
Navigate to WAF settings in Amplify console
Enable protection against DDoS attacks,
Configure rate limiting and IP filtering as needed
Your static website is now successfully hosted using AWS S3 and Amplify with the following features:
- β Global content delivery
- β HTTPS encryption
- β Custom domain (if configured)
- β Automatic scaling
Your static website is now live and accessible through:
- S3 Website URL:
http://your-bucket-name.s3-website-region.amazonaws.com - Amplify URL:
https://your-app-id.amplifyapp.com - Custom Domain (if configured):
https://yourdomain.com
- Always use HTTPS in production
- Regularly review and update bucket policies
- Monitor access logs for unusual activity
- Enable CloudFront for better global performance
- Optimize images and assets for web delivery
- Implement proper caching strategies
- Monitor S3 storage and data transfer costs
- Set up billing alerts for unexpected charges
- Consider S3 storage classes for cost optimization
- 403 Forbidden Error: Check bucket policy and public access settings
- 404 Not Found: Verify index.html file exists and is properly named
- SSL Certificate Issues: Allow time for certificate provisioning (up to 24 hours)
# Sync local files to S3 bucket
aws s3 sync ./website s3://your-bucket-name
# List bucket contents
aws s3 ls s3://your-bucket-name --recursive
# Check bucket policy
aws s3api get-bucket-policy --bucket your-bucket-nameFeel free to contribute to this project by:
- Reporting issues
- Suggesting improvements
- Submitting pull requests.