Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a subdomain Hosted Zone using Cloud Formation

I'd like to create a Route53 Hosted Zone for a subdomain and NS record to parent domain.

Let's say I have:

example.com

and I want a hosted zone for subdomain:

build.example.com

Hosted Zone creation works:

ClusterHostedZone:
  Type: "AWS::Route53::HostedZone"
  Properties:
    Name: !Ref DomainName
    HostedZoneConfig:
      Comment: Managed by Cloud Formation
    HostedZoneTags:
      - Key: KubernetesCluster
        Value: !Ref KubernetesCluster

Delegating responsibility for the subdomain don't:

ParentHostedZoneClusterRecord:
  Type: "AWS::Route53::RecordSet"
  Properties:
    Name: !Ref DomainName
    Comment: Managed by Cloud Formation
    HostedZoneId: !Ref ParentHostedZoneID
    TTL: 30
    Type: NS
    ResourceRecords: !GetAtt ClusterHostedZone.NameServers

This is not implemented and I don't know how to get this information:

ResourceRecords: !GetAtt ClusterHostedZone.NameServers

Is this simple feature just missing in Cloud Formation?

like image 494
Paweł Prażak Avatar asked Dec 09 '16 11:12

Paweł Prażak


People also ask

Can I create multiple hosted zones for the same domain name?

You can create more than one hosted zone with the same name and add different records to each hosted zone. Route 53 assigns four name servers to every hosted zone, and the name servers are different for each hosted zone.


1 Answers

This is working for my, maybe your template is not working because you do not specify DependsOn and resources are not created in order.

stagingHostedZone:
    Type: 'AWS::Route53::HostedZone'
    Properties:
        HostedZoneConfig:
            Comment: Hosted zone for staging environment
        Name: staging.example.com

nsRootHostedZoneRecordSet:
    Type: 'AWS::Route53::RecordSet'
    Properties:
        HostedZoneId: Z25*********
        Name: staging.example.com.
        Type: NS
        TTL: '900'
        ResourceRecords: !GetAtt stagingHostedZone.NameServers
    DependsOn:
        stagingHostedZone
like image 73
Chemary Avatar answered Nov 09 '22 07:11

Chemary