This repository contains all the resources and steps needed to create a static website on AWS using S3, CloudFront, Route 53, and AWS Certificate Manager.
In this tutorial, we will walk you through the complete process of setting up a static website on AWS, including creating an S3 bucket, configuring CloudFront for global content delivery, setting up a custom domain with Route 53, and securing your site with HTTPS using AWS Certificate Manager.
- An AWS account
- Basic knowledge of AWS services
- Domain name registered (preferably managed by AWS Route 53)
- Open the AWS Management Console and navigate to S3.
- Create a new bucket with a unique name.
- Upload your website files to the bucket.
- Open the CloudFront console.
- Create a new CloudFront distribution.
- Configure the origin settings to point to your S3 bucket.
- Enable origin access control settings and create OAC
- Change the viewer protocol policy to Redirect HTTP to HTTPS
- Select Do not enable security protections on the Web Application Firewall(WAF)
- Add the custom domain name to the Alternate domain name(CNAME)
- Click on Request a Certificate to obtain an SSL certificate using AWS Certificate Manager.
- Request a public certificate
- Add the FQDN
- Validate the domain ownership as instructed.
- Create the record in Route 53
- Set the Default root object to index.html
- Create Distribution
- Update the S3 bucket with the provided policy
- Open the Route 53 console.
- Create a new hosted zone for your domain if not already done.
- Create a simple routing policy with an Alias record that points to your CloudFront distribution.
- (Optional) Create an S3 bucket named
www.yourdomain.com
for redirection. - Configure static website hosting to redirect to
https://yourdomain.com
. - Update Route 53 to point
www.yourdomain.com
to the redirection bucket.
By following this guide, you should have a fully functional static website hosted on AWS, secured with HTTPS, and served globally via CloudFront.
For a detailed walkthrough, follow this tutorial on YouTube: Watch the Tutorial
In this section, we will implement a visitor count tracking system using AWS API Gateway, Lambda, and DynamoDB.
In this section, we will implement a visitor count tracking system using AWS API Gateway, Lambda, and DynamoDB.
- Open the AWS Management Console.
- Navigate to DynamoDB.
- Create a new table named
visitorcounts
. - Set the primary key as
id
with typeString
. - Add an initial item with
id
set to0
andviews
set to0
.
- Open the AWS Management Console.
- Navigate to Lambda.
- Create a new Lambda function named
VisitorCountFunction
. - Set the runtime to Python 3.x.
- Use the code from
lambda.py
for the Lambda function. - Configure the Lambda function with an execution role that has access to DynamoDB.
-
Open the AWS Management Console.
-
Navigate to API Gateway.
-
Create a new API.
-
Create a new resource named
visitors
. -
Create a new GET method for the
visitors
resource. -
Integrate the GET method with the Lambda function
VisitorCountFunction
. -
Enable CORS for the GET method.
-
Add a mapping template for the GET method to pass query string parameters to the Lambda function:
{ "queryStringParameters": { "count": "$input.params('count')" } }
-
Deploy the API to a stage (e.g.,
prod
).
-
Add the code from
visitorcount.js
to your website to track unique visitors. -
Ensure you have an HTML element with
id="visitors"
where the count will be displayed:<div id="visitors"></div>
- Open your website in a browser.
- Verify that the visitor count is displayed and increments for unique visitors.
- Check that the count does not increment for returning visitors.