Using AWS to Host a Static Website - Part 5

Using AWS to Host a Static Website - Part 5

Table of Contents

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.

The Sequence

  1. Retrieve the Hosted Zone ID for the domain that will be used
  2. Create the SSL certificates for the apex domain and www
  3. Use DNS validation for the SSL certificates

Retrieve the Hosted Zone ID

This is easily done using the AWSCLI. This has been tested on MacOS.

aws route53 list-hosted-zones-by-name --dns-name nostrom0.cloud \
--query 'HostedZones[?Name==`nostrom0.cloud.`].Id' --output text --region us-east-1 | sed 's/\/hostedzone\///'

This command.

  1. Get the hosted zone information
  2. Filter for a specific domain e.g. nostrom0.cloud
  3. Extract just the ID
  4. Remove the ‘/hostedzone/’ prefix using sed

The CloudFormation Template

This CloudFormation template is available here.

AWSTemplateFormatVersion: "2010-09-09"
Description: "ACM Certificate with DNS Validation for domain and www subdomain"

Parameters:
  DomainName:
    Type: String
    Description: "The domain name for the certificate (e.g., example.com)"
  HostedZoneId:
    Type: String
    Description: "The Route 53 Hosted Zone ID"
  TagValue:
    Type: String
    Description: "The tag value for the certificate"

Resources:
  Certificate:
    Type: AWS::CertificateManager::Certificate
    Properties:
      DomainName: !Ref DomainName
      SubjectAlternativeNames:
        - !Sub "www.${DomainName}"
      ValidationMethod: DNS
      DomainValidationOptions:
        - DomainName: !Ref DomainName
          HostedZoneId: !Ref HostedZoneId
        - DomainName: !Sub "www.${DomainName}"
          HostedZoneId: !Ref HostedZoneId
      Tags:
        - Key: workload
          Value: !Ref TagValue

Outputs:
  CertificateArn:
    Description: "ARN of the created certificate"
    Value: !Ref Certificate

The parameter file.

[
    { 
        "ParameterKey": "DomainName", 
        "ParameterValue": "INSERT_DOMAIN_NAME" 
    },
    {
        "ParameterKey": "HostedZoneId",
        "ParameterValue": "INSERT_HOSTED_ZONE_ID"
    },
    {
        "ParameterKey": "TagValue",
        "ParameterValue": "INSERT_DOMAIN_NAME"
    }
]

Deploying the CloudFormation Template

aws cloudformation create-stack --stack-name STACKNAME --template-body file://acm-ssl-certificates.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 SSL Certificates using AWS Certificate Manager. In the next post I will walk through creating the Amazon CloudFront distribution.


Using AWS to Host a Static Website - Part 6

Related Posts

The AWS re:Invent 2024 Experience

The AWS re:Invent 2024 Experience

This was not the first time I had been to re:Invent and things have changed over the years. This is true of Las Vegas and re:Invent. In person, this is the third time with another time being the virtual event when the Covid pandemic was at its height.

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
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