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

aws-route53: fromHostedZoneAttributes() fails when multiple hosted zones with the same name exist #33026

Closed
1 task
chatii opened this issue Jan 21, 2025 · 3 comments
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/medium Medium work item – several days of effort p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@chatii
Copy link

chatii commented Jan 21, 2025

Describe the bug

Due to a mistake, multiple hosted zones with the same name were created (this was my error during operations).

In CDK, I used fromHostedZoneAttributes with both the zone name and zone ID specified to retrieve the correct single zone.
Since the zone ID is unique, I expected a single zone to be retrieved.
However, the result was an error indicating that multiple zones exist.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The hosted zone with the specified zone ID should be retrieved.

Current Behavior

Found zones: [{"Id":"/hostedzone/Zxxxxxx...","Name":"example.example.com",...},{"Id":"/hostedzone/Zyyyyyy...","Name":"example.example.com",...},{"Id":"/hostedzone/Zzzzzzz...",""Name":"example.example.com",...}] for dns:hbpcc-dev.com, privateZone:undefined, vpcId:undefined, but wanted exactly 1 zone

Reproduction Steps

The following code to create hosted zones is clearly incorrect from an operational standpoint, but should be able to reproduce the issue.

const zone1 = new PublicHostedZone(this, "Zone1", {
  zoneName: "foo.example.com",
});
const zone2 = new PublicHostedZone(this, "Zone2", {
  zoneName: "foo.example.com",
});

When two hosted zones with the same name have been created, attempting to retrieve one of them by specifying its hosted zone ID results in an error, as shown below.

const hostedZone = HostedZone.fromHostedZoneAttributes(this, "FromAttr", {
  hostedZoneId: "Zxxxxxxx....",
  zoneName: "foo.example.com",
});

Possible Solution

No response

Additional Information/Context

CDK CLI Version

2.172.0 (build 0f666c5)

Framework Version

No response

Node.js Version

v22.12.0

OS

macOS 15.2

Language

TypeScript

Language Version

5.7.2

Other information

No response

@chatii chatii added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 21, 2025
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Jan 21, 2025
@pahud pahud self-assigned this Jan 21, 2025
@pahud
Copy link
Contributor

pahud commented Jan 21, 2025

This works perfect for me in 2.176.0

Are you able to deploy my provided dummy stack below?

export class DummyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const zone1 = new r53.PublicHostedZone(this, "Zone1", {
      zoneName: "foo.mydemo.com",
    });
    new CfnOutput(this, "Zone1Id", { value: zone1.hostedZoneId });

    const zone2 = new r53.PublicHostedZone(this, "Zone2", {
      zoneName: "foo.mydemo.com",
    });
    new CfnOutput(this, "Zone2Id", { value: zone1.hostedZoneId });

    const importedZone = r53.HostedZone.fromHostedZoneAttributes(this, "importedZone", {
      hostedZoneId: 'Z0977484290BNLEFRSMK0', // or just zone1.hostedZoneId
      zoneName: "foo.mydemo.com",
    });

    new CfnOutput(this, "ImportedZoneId", { value: importedZone.hostedZoneId });
    new CfnOutput(this, "ImportedZoneName", { value: importedZone.zoneName });

  }
}

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 labels Jan 21, 2025
@pahud pahud removed their assignment Jan 21, 2025
@pahud pahud added effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 21, 2025
@chatii
Copy link
Author

chatii commented Jan 22, 2025

@pahud
Thank you for your reply.

I upgraded CDK (2.176.0) and tried both your example code and a demo that more closely resembles our actual code.
(creating PublicHostedZones with the same zoneName in multiple stacks, and then referencing them using fromPublicHostedZoneAttributes() in another stack)
As a result, it worked as expected.

The original code that experienced the issue can no longer be verified as the HostedZone was manually deleted for work purposes, so this issue can be considered resolved.

I express my gratitude and will close this issue.

@chatii chatii closed this as completed Jan 22, 2025
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/medium Medium work item – several days of effort p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants