Deploying a Static Website with Amazon S3 and CloudFront: A Step-by-Step Guide
A static website is one of the simplest projects you can build on AWS, but it introduces several important cloud concepts at the same time.
In this tutorial, we'll build a simple static website using Amazon S3 and Amazon CloudFront.
The basic architecture is:
User → CloudFront → S3
Amazon S3 stores the website files, while CloudFront distributes the content through AWS edge locations.
WHAT WE'LL BUILD
Our website will contain simple static files such as:
index.html
style.css
Images
JavaScript
style.css
Images
JavaScript
There is no application server or database.
This makes the architecture suitable for portfolios, documentation sites, landing pages, and other static content.
STEP 1: CREATE YOUR WEBSITE
Start with a simple index.html file.
Example:
<!DOCTYPE html>
<html>
<head>
<title>My AWS Website</title>
</head>
<body>
<h1>Hello from AWS!</h1>
<p>This website is hosted using Amazon S3 and CloudFront.</p>
</body>
</html>
<head>
<title>My AWS Website</title>
</head>
<body>
<h1>Hello from AWS!</h1>
<p>This website is hosted using Amazon S3 and CloudFront.</p>
</body>
</html>
Add your CSS, images, JavaScript, and other website files as needed.
STEP 2: CREATE AN S3 BUCKET
Create an S3 bucket to store your website files.
Choose the AWS Region deliberately because services and features can have Region-specific availability.
Give the bucket a meaningful name and keep track of the Region where you created it.
For a production website, consider your access-control requirements before making objects publicly accessible.
STEP 3: UPLOAD YOUR WEBSITE FILES
Upload your HTML, CSS, JavaScript, and image files to the S3 bucket.
At this point, Amazon S3 is responsible for storing your website content.
However, storing files and securely delivering them to visitors are separate concerns.
That's where CloudFront comes in.
STEP 4: CREATE A CLOUDFRONT DISTRIBUTION
Create a CloudFront distribution and configure your S3 bucket as the origin.
CloudFront can cache your website content at edge locations, helping deliver content efficiently to visitors.
Configure the default root object as:
index.html
For a production architecture, use the recommended S3 origin access configuration so that users access the content through CloudFront rather than exposing the S3 bucket unnecessarily.
STEP 5: CONFIGURE HTTPS
Use HTTPS when serving your website.
If you're using your own domain, you can use AWS Certificate Manager (ACM) to provision an SSL/TLS certificate and associate it with your CloudFront distribution.
HTTPS protects data in transit and provides visitors with a secure connection to your website.
STEP 6: CONFIGURE YOUR DOMAIN
If you own a domain, you can point it to your CloudFront distribution.
Amazon Route 53 can be used for DNS management, although you can also manage your domain's DNS through another provider.
Your architecture can then look like:
User → Your Domain → CloudFront → S3
STEP 7: TEST THE WEBSITE
Open the CloudFront distribution's domain name in your browser.
If everything is configured correctly, you should see your website.
Test:
The home page
CSS
Images
JavaScript
HTTPS
Different devices
CSS
Images
JavaScript
HTTPS
Different devices
Testing each component helps identify configuration problems before sharing the website publicly.
COMMON MISTAKES
1. Forgetting the Default Root Object
If index.html isn't configured as the default root object, visiting the distribution's root URL may not behave as expected.
Make sure CloudFront knows which file should be returned when someone accesses the root of your website.
2. Incorrect S3 Access Configuration
S3 access configuration can be confusing when you're first learning AWS.
Avoid making everything public simply because it makes the website work.
Understand how S3 permissions and CloudFront origin access work, and use the least amount of access required.
3. Cached Website Changes
CloudFront caches content.
If you update a file and don't immediately see the change, an older version may still be cached.
For production deployments, consider an appropriate cache invalidation or versioning strategy.
4. Forgetting About Costs
S3 and CloudFront are managed services, but they aren't automatically free for every workload.
Before deploying, understand the applicable pricing, Free Tier eligibility, data transfer, storage, requests, and other potential charges.
For a small learning project, monitor your usage and clean up resources when you're finished.
WHAT THIS PROJECT TEACHES
Although a static website is simple, the project introduces several important AWS concepts:
Object storage
Content delivery networks
DNS
HTTPS
SSL/TLS certificates
IAM and access control
Caching
AWS Regions
Cloud architecture
Cost management
Content delivery networks
DNS
HTTPS
SSL/TLS certificates
IAM and access control
Caching
AWS Regions
Cloud architecture
Cost management
That's what makes a static website such a useful first AWS project.
You start with a simple webpage and end up learning how multiple cloud services work together.
FINAL THOUGHTS
One of the best ways to learn cloud computing is to build something small and gradually make the architecture better.
A static website gives you exactly that opportunity.
Start with a single HTML file.
Then introduce S3.
Add CloudFront.
Configure HTTPS.
Connect a domain.
Finally, think about security, performance, monitoring, and cost.
The website may be simple, but the cloud concepts behind it provide a solid foundation for more complex architectures.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article