Aws-cdk: Route53: HostedZone.fromHostedZoneId() throws an error for cdk synth

Created on 15 Aug 2019  路  4Comments  路  Source: aws/aws-cdk

  • I'm submitting a ...

    • [x] :beetle: bug report
    • [ ] :rocket: feature request
    • [ ] :books: construct library gap
    • [ ] :phone: security issue or vulnerability => Please see policy
    • [ ] :question: support request => Please see note at the top of this template.
  • What is the current behavior?
    If the current behavior is a :beetle:bug:beetle:: Please provide the steps to reproduce

Example code:

const domainZone = route53.HostedZone.fromHostedZoneId(this, 'domain-zone', hostedZoneId);

cdk synth throws an error:

HostedZone.fromHostedZoneId doesn't support "zoneName"
  • What is the expected behavior (or behavior of feature suggested)?

fromHostedZoneId() should return a valid IHosted颅Zone object.

  • What is the motivation / use case for changing the behavior or adding this feature?

HostedZone is needed, for instance, for LoadBalancedFargateServiceProps (for the domainZone property).

  • Please tell us about your environment:

    • CDK CLI Version: 1.4.0 (build 175471f)
    • Module Version: 1.4.0
    • OS: OSX Mojave
    • Language: TypeScript
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

duplicate

Most helpful comment

@realharry for Hosted Zones there are 3 methods that accomplish very similar, but slightly different goals.

fromHostedZoneId(...) and fromHostedZoneName(...) will create a mock object with just the ZoneId or the ZoneName field present. These are useful if you need to supply a HostedZone object but you know that the resource that is accepting the HostedZone only needs access to one of those variables. This is done without having make an API call so it can be done entirely locally.

The third method is fromAttributes(...) that will take the attributes and perform an API call to determine which exact HostedZone is deployed and updates its behavior accordingly.

The first two methods create use different Classes of IHostedZone that throw an error if you use the wrong parameter (e.g. calling getName() when you used fromHostedZoneId())

All 4 comments

duplicate of https://github.com/aws/aws-cdk/issues/3558

using from_hostedzone_attributes() is the preferred method for fetching the hostedzone information

hey @realharry ,

As @rhboyd mentioned, this seems to be a duplicate. Please reopen if the behavior you're observing is unique and the direction provided in the related issue doesn't work for you.

@realharry for Hosted Zones there are 3 methods that accomplish very similar, but slightly different goals.

fromHostedZoneId(...) and fromHostedZoneName(...) will create a mock object with just the ZoneId or the ZoneName field present. These are useful if you need to supply a HostedZone object but you know that the resource that is accepting the HostedZone only needs access to one of those variables. This is done without having make an API call so it can be done entirely locally.

The third method is fromAttributes(...) that will take the attributes and perform an API call to determine which exact HostedZone is deployed and updates its behavior accordingly.

The first two methods create use different Classes of IHostedZone that throw an error if you use the wrong parameter (e.g. calling getName() when you used fromHostedZoneId())

Is there any way to get the HostedZone if I only have the ID? I was using fromHostedZoneId and got the same error, but then I switched to using fromAttributes and now I need to provide the name in addition to the ID :(

Was this page helpful?
0 / 5 - 0 ratings