Closed realharry closed 5 years ago
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 :(
@rhboyd fromHostedZoneName
seems to be got deprecated and seems to be fromHostedZoneName
is doing an actual API call, how are you dealing with it? thanks!
I just fell into the same trap two years after this problem was first reported. It would be nice if the docs were updated so everybody didn't have to get the error, search for it on google, and read a bunch of threads to find the explanation of this wacky function.
using from_hostedzone_attributes() is the preferred method for fetching the hostedzone information
Why is zone name required in addition to zone id? It's not required on the underlying resource (which is how I've worked around), ie:
CfnRecordSet.Builder.create(this, "PublicRoute53Alias")
.hostedZoneId(Fn.importValue("..."))
How is it possible to know that from_hostedzone_attributes()
is preferred? Short of hitting this error, pasting it into google, and spending time reviewing these tickets:
It feels something is wrong with the API, that documentation alone can only mitigate, yet all of these tickets are closed.
@adrian-skybaker domainZone
is already optional for ApplicationLoadBalancedServiceBase
at least in master. If you need to use an older version, you could create a class and mock it and will also work. Hopefully works for someone else:
class MockZone extends cdk.Resource implements IHostedZone {
public readonly hostedZoneId = ''
public readonly zoneName = ''
public get hostedZoneArn(): string { return '' }
}
new aws_ecs_patterns.ApplicationLoadBalancedFargateService(this,
'FargateService',
{
certificate: cert,
domainZone: new MockZone(this, 'mockzone'),
....
}
)
I just ran into this error as well-- I am trying to use route53.HostedZone.from_hosted_zone_id() and it fails with the following error when a ZoneID is provided: HostedZone.fromHostedZoneId doesn't support "zoneName"
Please reopen this and fix the docs
Responded and reopened here https://github.com/aws/aws-cdk/issues/8406
I'm submitting a ...
What is the current behavior? If the current behavior is a :beetle:bug:beetle:: Please provide the steps to reproduce
Example code:
cdk synth
throws an error:fromHostedZoneId()
should return a validIHostedZone
object.HostedZone
is needed, for instance, forLoadBalancedFargateServiceProps
(for thedomainZone
property).Please tell us about your environment:
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)