AWS Builder Center
Deploy a Static Website on AWS Using Amazon S3 and CloudFront

Deploy a Static Website on AWS Using Amazon S3 and CloudFront

Learn how to host a static website on Amazon S3 and deliver it globally using Amazon CloudFront. This step-by-step guide covers S3 bucket configuration, secure content delivery, CloudFront distribution, deployment, and best practices for building a reliable and scalable web hosting solution on AWS.

Deploy a Static Website on AWS Using Amazon S3 and CloudFront
Introduction
Have you ever wondered how to deploy a website without managing servers or maintaining infrastructure?
Amazon Web Services (AWS) provides several services that make website hosting simple, scalable, and cost-effective.
In this article, we will learn how to host a static website using Amazon S3 and Amazon CloudFront.
By the end of this tutorial, you will understand how to upload website files to Amazon S3, configure CloudFront for content delivery, and make your website accessible to users around the world.
1. Understanding the AWS Services
Before starting the implementation, let's understand the two main services.
Amazon S3
Amazon Simple Storage Service (Amazon S3) is an object storage service that allows us to store and retrieve files such as:
- HTML files - CSS files - JavaScript files - Images - Documents
We can use an S3 bucket to store the static files of our website.
Amazon CloudFront
Amazon CloudFront is a Content Delivery Network (CDN).
It delivers website content through geographically distributed edge locations, helping users access content with lower latency.
CloudFront also supports HTTPS and integrates with AWS security services.
2. Architecture Overview
Our deployment architecture will look like this:
User → Amazon CloudFront → Amazon S3
Here is how it works:
1. A user visits the website through a browser. 2. The request reaches Amazon CloudFront. 3. CloudFront checks whether the requested content is available in its cache. 4. If the content is not cached, CloudFront retrieves it from the S3 origin. 5. The content is delivered to the user.
We will use Origin Access Control (OAC) so that CloudFront can access the S3 bucket without making the bucket publicly accessible.
3. Prerequisites
Before beginning, make sure you have:
- An AWS account. - A basic understanding of HTML, CSS, and JavaScript. - A static website ready for deployment. - Access to the AWS Management Console.
For this tutorial, we will use a simple website containing three files:
- index.html - style.css - script.js
4. Create an Amazon S3 Bucket
Follow these steps:
1. Sign in to the AWS Management Console. 2. Search for Amazon S3. 3. Select Create bucket. 4. Enter a globally unique bucket name. 5. Select your preferred AWS Region. 6. Keep Block all public access enabled. 7. Create the bucket.
Important: We are keeping the bucket private because CloudFront will access it using Origin Access Control.
5. Upload Website Files
After creating the bucket:
1. Open your S3 bucket. 2. Select Upload. 3. Add your website files. 4. Select Upload.
Your bucket should now contain the website files.
Example structure:
my-website/ │ ├── index.html ├── style.css └── script.js
6. Create a CloudFront Distribution
Now we will configure Amazon CloudFront.
1. Open Amazon CloudFront in the AWS Console. 2. Select Create distribution. 3. Select your S3 bucket as the origin. 4. Configure Origin Access Control (OAC). 5. Select the option to restrict access to the S3 bucket through CloudFront. 6. Allow CloudFront to update the S3 bucket policy when prompted. 7. Set the Default root object to:
index.html
8. Choose HTTPS redirection for viewer access. 9. Create the distribution.
CloudFront will take some time to deploy the distribution.
Once deployed, you will receive a CloudFront distribution domain name.
Example:
7. Access Your Website
After the CloudFront distribution becomes available:
1. Copy the CloudFront distribution domain name. 2. Open it in your browser. 3. Your static website should load successfully.
Congratulations! Your website is now hosted using Amazon S3 and delivered through Amazon CloudFront.
8. Update Website Content
Whenever you make changes to your website, upload the updated files to your S3 bucket.
You can also use AWS CLI to synchronize your local website directory.
Example:
aws s3 sync ./my-website s3://YOUR_BUCKET_NAME --delete
To refresh cached content after deployment, create a CloudFront invalidation:
aws cloudfront create-invalidation \ --distribution-id YOUR_DISTRIBUTION_ID \ --paths "/*"
Replace the placeholder values with your actual bucket and distribution details.
9. Benefits of This Architecture
Using Amazon S3 with CloudFront provides several advantages:
- Scalability: Handles increasing website traffic without managing web servers. - Performance: CloudFront caches content at edge locations. - Security: Private S3 buckets can be accessed through CloudFront using OAC. - HTTPS Support: Secure communication between users and CloudFront. - Low Maintenance: No need to manage operating systems or web servers. - Cost Optimization: Pay for the AWS resources and usage according to the applicable pricing model.
10. Best Practices
When deploying websites on AWS, consider the following practices:
1. Keep S3 Block Public Access enabled. 2. Use Origin Access Control instead of public bucket access. 3. Enable HTTPS for website visitors. 4. Use appropriate CloudFront cache policies. 5. Configure monitoring using Amazon CloudWatch. 6. Avoid storing sensitive information in frontend JavaScript files. 7. Review AWS billing regularly to control costs.
Conclusion
In this tutorial, we learned how to deploy a static website using Amazon S3 and Amazon CloudFront.
We explored how S3 stores website files, how CloudFront distributes content globally, and how Origin Access Control helps protect private S3 content.
This is a useful architecture for personal portfolios, documentation websites, landing pages, and static frontend applications.
If you are starting your AWS cloud journey, try implementing this project yourself. Practical experience with AWS services is one of the best ways to improve your cloud computing skills.
Keep learning, keep building, and keep sharing your AWS journey!
References
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article