π AWS S3 Static Website Hosting Tutorial
π Complete Guide to Hosting Your Website on Amazon S3
Welcome to this comprehensive DevOps tutorial! In this guide, youβll learn how to host a static website using Amazon S3, one of the most cost-effective and scalable ways to deploy static websites.
π― What Youβll Learn
- Setting up an AWS S3 bucket for static website hosting
- Configuring bucket policies and permissions
- Uploading and managing website files
π Prerequisites
Before we begin, make sure you have:
- β An AWS account (Create one here)
- β Basic understanding of HTML/CSS
- β A web browser
- β The website files (Clone this repo)
π¬ Step-by-Step Tutorial
Step 1: Create an S3 Bucket
-
Login to AWS Console
- Navigate to AWS Console
- Search for βS3β in the services menu
-
Create New Bucket
- Click "Create bucket" - Bucket name: my-portfolio-website-[unique-suffix] - Keep default settings for now - Click "Create bucket"π‘ Pro Tip: Bucket names must be globally unique across all AWS accounts!
Step 2: Configure Bucket for Static Website Hosting
-
Navigate to Your Bucket
- Click on your newly created bucket
- Go to the βPropertiesβ tab
-
Enable Static Website Hosting
- Scroll down to "Static website hosting" - Click "Edit" - Select "Enable" - Index document: index.html - Error document: error.html (optional) - Click "Save changes" -
Note the Website Endpoint
- Copy the bucket website endpoint URL
- Format:
http://bucket-name.s3-website-region.amazonaws.com
Step 3: Configure Bucket Permissions
-
Disable Block Public Access
- Go to "Permissions" tab - Click "Edit" on "Block public access" - Uncheck all 4 options - Click "Save changes" - Type "confirm" when promptedβ οΈ Security Note: Only disable block public access for static website hosting. Never do this for buckets containing sensitive data!
-
Add Bucket Policy
- In "Permissions" tab, scroll to "Bucket policy" - Click "Edit" - Copy the policy from s3-bucket-policy.json - Replace "YOUR-BUCKET-NAME" with your actual bucket name - Click "Save changes"
Step 4: Upload Website Files
-
Upload Files Using AWS Console
- Go to "Objects" tab in your bucket - Click "Upload" - Click "Add files" and select index.html and styles.css - Leave all other settings as default - Click "Upload" -
Verify Upload
- Check that both files appear in your bucket - Both files should show as "Publicly accessible" - You can click on each file to verify they uploaded correctly
Step 5: Test Your Website
-
Access Your Website
- Use the S3 website endpoint URL from Step 2 - Example: http://my-portfolio-website-123.s3-website-us-east-1.amazonaws.com -
Verify Everything Works
- Check that the HTML loads correctly
- Verify CSS styles are applied
- Test responsive design on different devices
- Check browser developer tools for any errors
π Bucket Security
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}
π Troubleshooting
Common Issues
-
403 Forbidden Error
β Check bucket policy is correctly applied β Verify block public access settings β Ensure file permissions are correct -
404 Not Found
β Verify index.html exists in bucket root β Check static website hosting is enabled β Confirm bucket name matches exactly -
CSS Not Loading
β Check file path in HTML is correct β Verify CSS file was uploaded β Check browser developer tools for errors -
Website Endpoint Not Working
β Use website endpoint, not REST endpoint β Format: bucket-name.s3-website-region.amazonaws.com β Wait a few minutes for DNS propagation
π Additional Resources
AWS Documentation
π€ Contributing
Found an issue or want to improve this tutorial?
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
π Support
Need help with this tutorial?
- π¬ GitHub Issues: Create an issue
- π± Twitter: @devopsengineer
- πΌ LinkedIn: Connect with me
π License
This tutorial is open source and available under the MIT License.
π Congratulations!
Youβve successfully learned how to host a static website on AWS S3! This is a fundamental skill in modern DevOps and cloud engineering. Keep practicing and exploring more AWS services to build your cloud expertise.
Remember: The best way to learn DevOps is by doing. Try modifying the code, experiment with different configurations, and most importantly, break things and fix them β thatβs how you really learn!
Made with β€οΈ for the DevOps community by Rushikesh