question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Route53] HostedZone.hostedZoneNameServers property does not synthesize correctly

See original GitHub issue

The synthesized template contains a CDK Token rather than a cloudformation Fn::GetAtt statement when referencing the hostedZoneNameServers property of a HostedZone construct.

Reproduction Steps

    const zone = new HostedZone(this, 'HostedZone', {
      zoneName: 'example.com',
    })

    const nameServer1 = zone.hostedZoneNameServers ? zone.hostedZoneNameServers[0] : 'UNDEFINED'

    new CfnOutput(this, 'ZoneId', { value: zone.hostedZoneId })
    new CfnOutput(this, 'NameServer1', { value: nameServer1 })

What did you expect to happen?

NameServer1 Cfn output in the template should consist of a Fn::GetAtt expression, not a CDK token.

What actually happened?

Synthesized template contains:

  "Outputs": {
    "HostedZoneId": {
      "Value": {
        "Ref": "HostedZoneDB99F866"
      }
    },
    "NameServer1": {
      "Value": "#{Token[TOKEN.93]}"
    }
  },

NOTE: Also expect this to work if zone.hostedZoneNameServers is used where an array is expected.

Environment

  • CLI Version : 1.70.0
  • Framework Version: 1.70.0
  • Node.js Version: v14.2.0
  • OS :MacOS Catalina 10.15.7
  • Language (Version): typescript 4.0.3

Other

A public HostedZone will always have nameservers, a private zone will not. Perhaps change the semantics so that the zone.hostedZoneNameServers property is guaranteed to be defined in a public zone. This might make it easier to synthesize correctly?


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
dio833commented, Jan 2, 2021

I encountered a similar problem and found it here. @balkat solved my problem, thanks!

I just directly use hostedZoneNameServers property.

const nsArray = zone.hostedZoneNameServers as string[];
const nsList = cdk.Fn.join(',', nsArray );
new cdk.CfnOutput(this, 'NameServerList', { value: nsList });
1reaction
balkatcommented, Oct 27, 2020

And for completeness, I was able to deploy by adding extra code to join the array returned by GetAtt into a string:

    const zoneResource = zone.node.defaultChild as CfnResource
    const nsAttr = Fn.getAtt(zoneResource.logicalId, 'NameServers') as unknown
    const nsAttrArray = nsAttr as string[]
    const nsList = Fn.join(',', nsAttrArray)
    new CfnOutput(this, 'NameServerList', { value: nsList })

Synthed template:

  "Outputs": {
    "NameServerList": {
      "Value": {
        "Fn::Join": [
          ",",
          {
            "Fn::GetAtt": [
              "HostedZoneDB99F866",
              "NameServers"
            ]
          }
        ]
      }
    },

Output from cloudformation deployment:

HostedZone-Zone-cbutcher.NameServerList = ns-1056.awsdns-04.org,ns-153.awsdns-19.com,ns-1644.awsdns-13.co.uk,ns-990.awsdns-59.net

Read more comments on GitHub >

github_iconTop Results From Across the Web

class HostedZone (construct) · AWS CDK
Import a Route 53 hosted zone defined either outside the CDK, or in a different CDK stack. Use when hosted zone ID is...
Read more >
AWS CDK -- How do I retrieve my NS Records from my newly ...
I did try the hostedZoneNameServers property. However, it doesn't seem to return anything. const zone = route53.HostedZone.fromLookup(this, ' ...
Read more >
How To Use AWS Route53 Wildcard Subdomains With CDK
The Hosted Zone is easiest to set up if you have a domain that is managed by Route 53 and that you don't...
Read more >
awsroute53 - Go Packages
Construction properties for a ARecord. Example: import apigw "github.com/aws/aws-cdk-go/awscdk" var zone hostedZone var restApi lambdaRestApi route53.
Read more >
AWS::Route53::HostedZone - Amazon CloudFormation
You can't convert a public hosted zone to a private hosted zone or vice versa. ... the NS and SOA records are not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found