Using AWS to Host a Static Website - Part 7

Using AWS to Host a Static Website - Part 7

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

  1. Create the alias DNS entry for the apex domain
  2. 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.

Related Posts

TCP/IP Subnetting

TCP/IP Subnetting

If you’ve ever dived into networking or IT, you’ve likely come across the concept of subnetting. For many folks, subnetting can feel like a maze of numbers, acronyms, and rules. But once you understand the logic behind it, it becomes a lot easier to understand and do without using online calculators.

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

Using AWS to Host a Static Website - Part 5

In part 4 I did a walk through of creating an Amazon Route 53 public hosted zone. If AWS is registrar, that step is not required as AWS create it as part of the registration. It just made sense to walk through the steps for completeness. In this post I am walking through the steps to create SSL certificates and use DNS validation. This is achieved using AWS Certificate Manager.

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

Using AWS to Host a Static Website - Part 1

For years I have been uses various platforms to host a static website and one of the easiest ways, for me, has been to use AWS services to do so. At the core of it, there is Amazon S3 which is cheap and easy to configure as a static website. You can add several other AWS services to this to provide a scalable and robust solution for hosting a static website.

Read More