Open hoagsie opened 2 years ago
Through trial and error I was able to find the domainNameAliasTarget
and domainNameAliasHostedZoneId
values in both the AWS Console and in the CLI, though they are not explicitly labeled as such and the documentation for the DomainName.fromDomainNameAttributes
method does not indicate where these values come from.
If you are using the AWS Console, the value of the API Gateway domain name in the Configurations page for a custom domain is what should be mapped to the domainNameAliasTarget
and the Hosted Zone ID value on the same page is what should be mapped to the domainNameAliasHostedZoneId
.
If you are using the CLI, then the value of regionalDomainName/distributionDomainName is what should be mapped to the domainNameAliasTarget
and the value of regionalHostedZoneId/distributionHostedZoneId is what should be mapped to the domainNameAliasHostedZoneId
If these are the correct sources for these values, I would be happy to open a PR to update the docs for the DomainNameAttributes
interface with this information
I'm struggling with this as well. We have multiple API Gateways (microservices) we want to tie together under one domain. One top level project provisions the custom domain and Route53 record. The other projects need to import DomainName. I don't see how to programmatically, through CDK, get the values domainNameAliasTarget
and domainNameAliasHostedZoneId
. It would be super swell if there was a way to import a Route53 Record and retrieve this info.
https://github.com/aws/aws-cdk/issues/4887#issuecomment-590143444 helped
This works:
new CfnBasePathMapping(this, 'basePath', {
domainName: 'example.com',
basePath: 'basePath',
restApiId: restApiId,
stage: 'prod',
});
As suggested in #6804 & https://github.com/aws/aws-cdk/issues/4887#issuecomment-580433107, domainNameAliasTarget
& domainNameAliasHostedZoneId
, I think, should be optional in DomainName.fromDomainNameAttributes
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.DomainName.html#static-fromwbrdomainwbrnamewbrattributesscope-id-attrs
I can see two different requests here:
1) Clear up documentation specifying where exactly you can get the values for domainNameAliasTarget
or domainNameHostedZoneId
2) Feature request to make these properties optional
The first one is pretty easy to clean up, if someone here could submit a PR for that, it would be wonderful!
As for the second request - The CDK generally only requires the name or id when importing resources. I think there's enough customer requests and merit to the idea that we should make these properties optional.
It looks like I can put "dummy" values. Here my code:
const domainNameObj = DomainName.fromDomainNameAttributes(this, 'domain', {
domainName,
domainNameAliasHostedZoneId: 'dummy', // it should be optional
domainNameAliasTarget: 'dummy', // it should be optional
});
new BasePathMapping(this, 'mapping', {
domainName: domainNameObj,
basePath,
restApi,
});
It seems to work as expected.
Can someone confirm that domainNameAliasHostedZoneId
and domainNameAliasTarget
are not required in this scenario?
See also #6804
hey guys, I was struggling with the same issue and figured out that I need to first create a domain and export its domainNameAliasDomainName
property from the source stack which will be used as domainNameAliasTarget
when importing domainName
into the other stack. It's name doesn't reflect what it is but from AWS's own documentation from DomainName has a definition as;
The Route53 alias target to use in order to connect a record set to this domain through an alias.
Here is my stackoverflow post which contains examples if it helps.
@davideicardi I have replicated what you did as well, it works great. I agree, those fields should be optional.
link to reference doc page
https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html
Describe your issue?
Similar Issues
https://github.com/aws/aws-cdk/issues/6804 https://github.com/aws/aws-cdk/issues/4887
Question
When doing an import how are you supposed to derive
domainNameAliasTarget
? Can an example be given for how this is sourced?Explanation
domainNameAliasHostedZoneId
is a private value for both Regional and Edge endpoints. Meaning, ZoneZ1UJRXOUMOOFQ8
does not belong to any of my accounts and is called out the docs as a hard-coded value. The responses in those other two issues are assuming you're creating a new APIGW Domain and not importing one. My use-case requires importing rather than creating a new domain. The referenced doc page doesn't even address the field at all even though it does others. Executingaws apigateway get-domain-name
does not reveal what the alias target is. Trying to query the Route 53 service with theZ1UJRXOUMOOFQ8
zone ID naturally results in anAccessDenied
error.