Skip to content

aws-cdk-lib: CrossAccountZoneDelegationRecord does not validate hostedZoneNameServers #28581

@u873838

Description

@u873838

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:

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.

Metadata

Metadata

Assignees

Labels

aws-cdk-libRelated to the aws-cdk-lib packagebugThis issue is a bug.effort/mediumMedium work item – several days of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions