-
Notifications
You must be signed in to change notification settings - Fork 4.5k
aws-cdk-lib: CrossAccountZoneDelegationRecord does not validate hostedZoneNameServers #28581
Description
Describe the bug
Our deployment failed when trying to use CrossAccountZoneDelegationRecord with an IHostedZone that did not have hostedZoneNameServers set. In our particular case, IHostedZone came from PublicHostedZone.fromHostedZoneAttributes.
Expected Behavior
Either an error should be thrown during the CDK build process, or the construct should support an IHostedZone without unset.
Current Behavior
We received the error during our CF deployment:
[FAILED] from custom resource. Message returned: TypeError: Cannot read properties of undefined (reading 'map') at cfnEventHandler
Reproduction Steps
Our internal CDK code looked something like:
const hostedZone = route53.PublicHostedZone.fromHostedZoneAttributes(this, 'WebsiteHostedZone', {
hostedZoneId,
zoneName: 'same.example.com'',
});
new CrossAccountZoneDelegationRecord(this, 'CrossAccountZoneDelegation', {
// ...
parentHostedZoneName: 'same.example.com',
childHostedZoneName: hostedZone,
});Possible Solution
This line forcefully asserts that hostedZoneNameServers is defined:
| DelegatedZoneNameServers: props.delegatedZone.hostedZoneNameServers!, |
Then the handler reads from that possibly undefined array:
aws-cdk/packages/aws-cdk-lib/aws-route53/lib/cross-account-zone-delegation-handler/index.ts
Line 58 in d69c51a
| ResourceRecords: DelegatedZoneNameServers.map(ns => ({ Value: ns })), |
Additional Information/Context
No response
CDK CLI Version
2.77.0
Framework Version
No response
Node.js Version
v18.12.1
OS
Ubuntu 22.04.3
Language
TypeScript
Language Version
No response
Other information
We are an internal AWS team using SuperNova.