DevOps
Deploy and Host a Static Web Application on AWS S3 Easily
Introduction
Hosting a web application on Amazon S3 (Simple Storage Service) is a straightforward process, especially for static web applications (e.g., those built with HTML, CSS, JavaScript). S3 is designed to store and serve static content efficiently, making it a cost effective solution for hosting websites or single page applications (SPAs). Below, I’ll walk you through the steps to host a web application on S3.
Steps to Host a Web Application on S3
Hosting a web application on Amazon S3 is a cost-effective and scalable solution for serving static websites. Follow these steps to set up and deploy your application efficiently.
Prepare Your Web Application Files
- Ensure your web application consists of static files (e.g., index.html, styles.css, app.js etc.).
- If you’re using a framework like React, Angular or Vue build the project (e.g., npm run build) to generate a production ready set of static files.
- Test locally to confirm everything works as expected.
Create an S3 Bucket
- Log in to the AWS Management Console and navigate to the S3 service.
- Click Create Bucket.
- Provide a unique bucket name (e.g., my-web-app-2025).
- Note: Bucket names must be globally unique across all AWS users.
- Choose a region (preferably one close to your target audience).
- Leave the default settings for now, but uncheck "Block all public access" if prompted (you’ll configure permissions next).
- Click Create Bucket.
Enable Static Website Hosting
- Open your newly created bucket in the S3 console.
- Go to the Properties tab.
- Scroll down to the Static website hosting section and click Edit.
- Select Enable.
- Specify the Index document (e.g., index.html), which is the entry point for your web app.
- Optionally, provide an Error document (e.g., error.html) for handling 404 errors.
- Save changes.
- Note the Endpoint URL provided (e.g., http://my-web-app-2025.s3-website-us-east-1.amazonaws.com). This is how you’ll access your site.
Upload Your Files
- Go to the Objects tab in your bucket.
- Click Upload and drag your web application files (e.g., the contents of your build or dist folder) into the upload area.
- Ensure index.html is at the root of the bucket (not in a subfolder) unless you plan to adjust the configuration.
- Click Upload to complete the process.
Set Permissions for Public Access
By default, S3 buckets are private. To make your web app publicly accessible:
Go to the Permissions tab of your bucket.
Edit the Bucket Policy and add the following JSON policy (replace my-web-app-2025 with your bucket name):
{ "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::my-web-app-2025/*" } ]}
Save the policy.
This allows anyone to read objects (files) in your bucket, which is necessary for a public website.
Test Your Web Application
- Open the endpoint URL from Step 3 in a browser (e.g., http://my-web-app-2025.s3-website-us-east-1.amazonaws.com).
- Verify that your web application loads correctly.
- If you encounter issues, double-check file names (S3 is case-sensitive), permissions, or whether index.html is correctly set as the index document.
Optional: Configure a Custom Domain (Bonus)
If you want to use a custom domain (e.g., www.mywebapp.com):
Register your domain (e.g., via Route 53 or another registrar).
In S3, name your bucket exactly as your domain (e.g., www.mywebapp.com).
Update the bucket policy and static website hosting settings as above.
Use Route 53 (or your DNS provider) to create a CNAME or alias record pointing to the S3 endpoint.
This step requires additional AWS services like Route 53 and possibly a CloudFront distribution for HTTPS.
Tips
- Dynamic Content: S3 only supports static files. For dynamic functionality (e.g., APIs), integrate with AWS Lambda and API Gateway.
- HTTPS: For security, consider adding CloudFront (AWS’s CDN) in front of S3 to enable HTTPS and improve performance.
- Cost: S3 is inexpensive for small-scale hosting, but monitors usage if traffic spikes.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our DevOps Expertise.
Comment