You can create hosted zones with CloudFormation templates by using the resource type AWS::Route53::HostedZone:
Resources:
CloudMaterialsHostedZone:
Type: "AWS::Route53::HostedZone"
Properties:
HostedZoneConfig:
Comment: HostedZone for CloudMaterials.com
Name: cloudmaterials.com
We will also add an Outputs section, for returning the HostedZoneID and nameservers:
Outputs:
HostedZoneId:
Value: !Ref CloudMaterialsHostedZone
Description: HostedZone for cloudmaterials.com
HostedZoneNameservers:
Value: !Join
- ','
- !GetAtt CloudMaterialsHostedZone.NameServers
Description: HostedZone Nameservers for cloudmaterials.com
The value of an Outputs field can only be of the string type. The property Nameservers, however, returns a list of nameservers. Therefore, we need to use a join function to add them to a string, separated by ,.
Deploy the stack by using deploy-stack, and verify it by using describe-stacks. You can also verify this from the Route 53 dashboard in the AWS Management Console. The Outputs section of the response should appear as follows:
You can now configure these nameservers with your domain registrar.