Using AWS to Host a Static Website - Part 7
- Jamie Tyler
- Aws
- January 2, 2025
Table of Contents
In part 6 I created the CDN distribution using Amazon CloudFront which tied the SSL certificates, HTTP to HTTPS redirection and the static content on the Amazon S3 bucket together. In this post, I am creating the Amazon Route 53 alias records to point at the distribution that I created.
The Sequence
- Create the alias DNS entry for the apex domain
- Create the alias DNS entry for www
The CloudFormation Template
This CloudFormation template is available here.
AWSTemplateFormatVersion: "2010-09-09"
Description: "Create DNS records for CloudFront distribution with existing S3 bucket as origin"
Resources:
ApexAliasRecord:
Type: "AWS::Route53::RecordSet"
Properties:
HostedZoneId: !Ref HostedZoneId # Your Route 53 hosted zone
Name: !Ref DomainName
Type: A
AliasTarget:
DNSName: !Ref CloudFrontDomainName
HostedZoneId: Z2FDTNDATAQYW2 # Fixed CloudFront hosted zone ID
EvaluateTargetHealth: false
WwwAliasRecord:
Type: "AWS::Route53::RecordSet"
Properties:
HostedZoneId: !Ref HostedZoneId
Name: !Sub "www.${DomainName}"
Type: A
AliasTarget:
DNSName: !Ref CloudFrontDomainName
HostedZoneId: Z2FDTNDATAQYW2 # Fixed CloudFront hosted zone ID
EvaluateTargetHealth: false
Parameters:
HostedZoneId:
Type: String
Description: "The ID of your Route 53 hosted zone"
DomainName:
Type: String
Description: "The apex domain name (e.g., example.com)"
CloudFrontDomainName:
Type: String
Description: "The CloudFront distribution domain name"
The parameter file.
[
{
"ParameterKey": "HostedZoneId",
"ParameterValue": "INSERT_HOSTED_ZONE_ID"
},
{
"ParameterKey": "DomainName",
"ParameterValue": "INSERT_DOMAIN_NAME"
},
{
"ParameterKey": "CloudFrontDomainName",
"ParameterValue": "INSERT_CLOUDFRONT_DOMAIN_NAME"
}
]
Deploying the CloudFormation Template
aws cloudformation create-stack --stack-name STACKNAME --template-body file://dns-entries.yaml \
--parameters file://parameters.json --region us-east-1
The STACKNAME can be whatever you choose but I recommend it is meaningful.
Conclusion
This concludes this series of posts. By walking through each post a static website can be deployed on AWS. As I have mentioned before I use Hugo to create and update the static content associated with renegade.cloud so I don’t need to spend time building HTML, CSS or Javascript files.