Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route53 ZoneDelegationRecord doesn't accept PublicHostedZone hostedZoneNameServers #1847

Closed
skorfmann opened this issue Feb 24, 2019 · 5 comments · Fixed by #1853
Closed
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug.

Comments

@skorfmann
Copy link
Contributor

Given I have two zones, where I want to delegate from one zone to the other, I can't use the L2 Route53 ZoneDelegationRecord.

screenshot 2019-02-24 at 12 51 37
screenshot 2019-02-24 at 12 51 50

So, this issue appears to be, that hostedZoneNameServers returns null | string[] rather than just string[]. I tried this:

{
  zone: mainZone,
  delegatedZoneName: previewZone.zoneName,
  nameServers: <string[]>mainZone.hostedZoneNameServers
}

While this satisfies the type, it fails when actually running it via the CDK.

What I ended up doing for now:

const zoneDelegationResource = zoneDelegation.node.findChild(
  "Resource"
) as route53.CfnRecordSet;

zoneDelegationResource.addPropertyOverride(
  "ResourceRecords",
  mainZone.hostedZoneNameServers
);
@RomainMuller RomainMuller added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Feb 25, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Feb 25, 2019

While this satisfies the type, it fails when actually running it via the CDK.

Could you give more details on this? Because it sure seems like that should work.

@rix0rrr rix0rrr added the bug This issue is a bug. label Feb 25, 2019
@RomainMuller
Copy link
Contributor

RomainMuller commented Feb 25, 2019

@skorfmann as mentioned in the documentation the nameServers attribute is not available for private hosted zones and hosted zones that are imported from another stack.

In your particular case, you can assert the name servers are present by simply adding an exclamation mark:

const zoneDelegation = new route53.ZoneDelegationRecord(this, 'PreviewZoneDelegation', {
  zone: mainZone,
  delegatedZoneName: previewZone.zoneName,
  nameServers: previewZone.hostedZoneNameServers! // <-- the "!" means "I know this won't be undefined"
});

Also - note that I changed the nameServers property to be those of the previewZone, as the delegation record is created in the delegating zone and point to the delegated servers.

@RomainMuller
Copy link
Contributor

I've tested this and it appears there is a bug related to how the tokens are handled here, which causes the code to crash with an obscure error. I am preparing a fix for this.

RomainMuller added a commit that referenced this issue Feb 25, 2019
When creating delegation relationship between two `PublicHostedZone`s,
one can now use `zone.delegateTo(otherZone)` instead of manually
creating the `ZoneDelegationRecord` insteance. This reduces the risk of
passing the incorrect name server, or hosting the record on the wrong
end of the relationship (DNS is hard!)

Additionally, fixes a bug in which it was not possible to create a zone
delegation record using a `IHostedZone.hostedZoneNameServers` property
as the array was mapped, which caused the `Fn::GetAtt` stringified list
token to become corrupted.

Fixes #1847
@RomainMuller
Copy link
Contributor

#1853 includes a fix for the bug in question, and also introduces an API such that you could:

mainZone.delegateTo(previewZone);

@skorfmann
Copy link
Contributor Author

In your particular case, you can assert the name servers are present by simply adding an exclamation mark:

Sweet, didn't know that.

#1853 includes a fix for the bug in question, and also introduces an API such that you could:

Awesome, thank you!

RomainMuller added a commit that referenced this issue Feb 28, 2019
When creating delegation relationship between two `PublicHostedZone`s,
one can now use `zone.addDelegation(otherZone)` instead of manually
creating the `ZoneDelegationRecord` insteance. This reduces the risk of
passing the incorrect name server, or hosting the record on the wrong
end of the relationship (DNS is hard!)

Additionally, fixes a bug in which it was not possible to create a zone
delegation record using a `IHostedZone.hostedZoneNameServers` property
as the array was mapped, which caused the `Fn::GetAtt` stringified list
token to become corrupted.

Fixes #1847
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants