Using AWS to Host a Static Website - Part 4

Using AWS to Host a Static Website - Part 4

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.


Using AWS to Host a Static Website - Part 5

Related Posts

How to use a Password Manager to Store AWS Credentials

How to use a Password Manager to Store AWS Credentials

I like to have a way of avoiding having to have access_key_ids and secret_access_keys locally configured on my Mac.

Read More
Using AWS to Host a Static Website - Part 6

Using AWS to Host a Static Website - Part 6

In part 5 I created the SSL certificates to use with the static website. In this post, I am going to deploy Amazon CloudFront for the CDN portion. Before I do that, I am going to upload the static HTML files that will be rendered.

Read More
Using AWS to Host a Static Website - Part 2

Using AWS to Host a Static Website - Part 2

In Part 1 I talked about the AWS services used to host a static website and the use of Infrastructure-as-Code (“IaC”) to deploy and, ultimately maintain the infrastructure that underpins it. In this post, I am going to talk about the sequence that the AWS services need to be created in.

Read More