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): Cannot call addDelegation on hosted zones assembled from attributes #28245

Closed
moltar opened this issue Dec 4, 2023 · 2 comments
Closed
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@moltar
Copy link
Contributor

moltar commented Dec 4, 2023

Describe the bug

A public hosted zone, assembled from attributes implements IHostedZone, which has the addDelegation method. This method requires the knowledge of hostedZoneNameServers, which I believe is not available when assembling from attributes.

Expected Behavior

One of:

  1. Have another interface without the addDelegation method.
  2. The addDelegation method should correctly check for hostedZoneNameServers and throw a meaningful error.

Current Behavior

An ambigous and user-hostile (due to the lack of source maps) error is thrown:

TypeError: Cannot read properties of undefined (reading 'map')
    at ZoneDelegationRecord (.../node_modules/.pnpm/[email protected][email protected]/node_modules/aws-cdk-lib/aws-route53/lib/record-set.js:1:10952)

Reproduction Steps

const iTestHostedZone = PublicHostedZone.fromHostedZoneAttributes(this, 'ITestHostedZone', {
  hostedZoneId: INTEGRATION_TEST_ROOT_HOSTED_ZONE_ID,
  zoneName: INTEGRATION_TEST_ROOT_ZONE_NAME,
})

const testHostedZone = new PublicHostedZone(this, 'HostedZone', {
  zoneName: [
    'foo',
    INTEGRATION_TEST_ROOT_ZONE_NAME,
  ].join('.'),
})

testHostedZone.addDelegation(iTestHostedZone)

Possible Solution

public addDelegation(delegate: IPublicHostedZone, opts: ZoneDelegationOptions = {}): void {
new ZoneDelegationRecord(this, `${this.zoneName} -> ${delegate.zoneName}`, {
zone: this,
recordName: delegate.zoneName,
nameServers: delegate.hostedZoneNameServers!, // PublicHostedZones always have name servers!
comment: opts.comment,
ttl: opts.ttl,
});
}
}

  1. Do not use bang to satisfy the compiler (delegate.hostedZoneNameServers! <---), this is already a code smell.
  2. Use proper assertion to both provide user a good error message, and type narrow: assert(delegate.hostedZoneNameServers, 'No name servers')

Additional Information/Context

N/A

CDK CLI Version

2.111.0

Framework Version

2.100.0

Node.js Version

v18.12.1

OS

macOS

Language

TypeScript

Language Version

No response

Other information

No response

@moltar moltar added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 4, 2023
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Dec 4, 2023
@moltar
Copy link
Contributor Author

moltar commented Dec 4, 2023

Closing as a duplicate of #3558

@moltar moltar closed this as completed Dec 4, 2023
Copy link

github-actions bot commented Dec 4, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant