amazon-web-servicesaws-cloudformationamazon-route53troposphere

troposphere to create alias A record when you have hosted zones with same name


funsetgroup = template.add_resource(RecordSet(
        'funsetgroup',
        HostedZoneName=Join('', [Ref(hostedzone), "."]),
        Comment='Hosted Zone Name',
        Type="A",
        Name=Join('fun.', [Ref(hostedzone), "."]),
        AliasTarget=AliasTarget(
            HostedZoneId=GetAtt(myelb, "CanonicalHostedZoneNameID"),
            DNSName=GetAtt(myelb, "DNSName"),
        )))

In this troposphere code I am trying to create an Alias A record for my hosted zone say, example.com. But I have 2 hosted zones with the same name(hosted zone Id's will be different). Although I explicitly mention the hosted zone id cloud formation doesn't create the stack saying "duplicate hosted zone found". I also tried just mentioning the hosted zone id without the hostedzone name that fails as well.


Solution

  • Did you also try using HostedZoneId instead of HostedZoneName in the RecordSet? This should work - we created Alias records in different zones with the same name in Empire all the time, and our code there uses Cloudformation as well (with a shim similar to troposphere - so much so, we call it troposphere). You can see that here:

    https://github.com/remind101/empire/blob/ac27a91f3a5131b18700c350ca510d1befed7a51/scheduler/cloudformation/template.go#L647

    Doing something similar in troposphere should work fine - just use HostedZoneId both in the RecordSet and the AliasTarget objects.