Using AWS to Host a Static Website - Part 4
- Jamie Tyler
- Aws
- December 23, 2024
Table of Contents
In part 3 I walked through the creation of the Amazon S3 bucket where the static website content will reside. In this post I will walk through using CloudFormation to create an Amazon Route 53 public hosted zone. This is automatically created when a domain is registered using Amazon Route 53 so this is for completeness and is not required for this series of posts.
The Sequence
This is a very straight forward process and only has one step which is to create the public hosted zone. However, I am introducing the use of a parameter file to simplify the AWSCLI. This is in the JSON format and will only have one parameter. The public hosted zone I am creating is foobar.com which is made up and is likely to exist but because I am not changing the name server details at the registrar level it will not interfere with anything. However I recommend you use a domain owned by you if you want to try this out.
Note
AWS reserve the use of test.com so the CLoudFormation template will fail if it is used.
The CloudFormation Template
This CloudFormation template is available here.
AWSTemplateFormatVersion: "2010-09-09"
Description: "CloudFormation template to create Route 53 public hosted zone"
Parameters:
DomainName:
Type: String
Description: The domain name for the hosted zone (e.g., example.com)
Resources:
PublicHostedZone:
Type: AWS::Route53::HostedZone
Properties:
Name: !Ref DomainName
HostedZoneConfig:
Comment: !Sub "Public hosted zone for ${DomainName}"
Outputs:
HostedZoneId:
Description: "Hosted Zone ID"
Value: !Ref PublicHostedZone
NameServers:
Description: "Nameservers for the hosted zone. Update these at your domain registrar."
Value: !Join
- ", "
- !GetAtt PublicHostedZone.NameServers
The parameter file is very simple.
[{ "ParameterKey": "DomainName", "ParameterValue": "foobar.com" }]
Deploying the CloudFormation Template
As mentioned, the parameter is stored in a file so the deployment is slightly different to accommodate this change.
aws cloudformation create-stack --stack-name STACKNAME --template-body file://route53-public-zone.yaml \
--parameters file://parameters.json --region us-east-1
The STACKNAME can be whatever you choose but I recommend it is meaningful.
Conclusion
A very simple CloudFormation template and a parameter file there is a repeatable way of setting up a Route 53 public hosted zone. In the next post I will walk through setting up SSL certificates for use with the domain using AWS Certificate Manager.