We can create a template for RecordSet, given as follows:
- Start the template with the template version and a description (optional).
- Define the parameters (of the string type) for the root domain name, the sub-domain name, and the S3 hosted zone ID.
Note that the S3 hosted zone is static, based on the region (for example, Z2FDTNDATAQYW2 for ap-south-1).
- Define a resource of the type RecordSetGroup type to add A records for the domains:
Resources:
QuizzerCloudDNS:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: !Sub
- ${DomainName}.
- DomainName: !Ref RootDomainName
Comment: Zone apex alias.
RecordSets:
-
Name: !Ref RootDomainName
Type: A
AliasTarget:
HostedZoneId: !Ref RecordHostedZoneId
DNSName: !ImportValue CloudFrontDomainName
-
Name: !Ref SubDomainName
Type: A
AliasTarget:
HostedZoneId: !Ref RecordHostedZoneId
DNSName: !ImportValue CloudFrontDomainName
The HostedZoneName is the domain name, followed by a dot (.), and the RecordHostedZone ID is a constant value for all of the CloudFront distributions
- Define an Outputs section to return the URLs (optional).
- Execute the aws cloudformation create-stack by passing the parameters, and then verify the following:
After executing the create-stack sub-command, check the status by using the describe-stacks sub-command. Once it is successful, it should return a response with the following Outputs section:
We can verify that everything worked by going to quizzercloud.com and www.quizzercloud.com in a browser, as shown in the following screenshot:
Note that the URL is not secure. Even if we use HTTPS, we will still get a Not Secure message, as we do not have a valid certificate for this domain. We will look at how to fix this in the next recipe.