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-apigateway): Where does domainNameAliasTarget come from for imports? #19045

Open
hoagsie opened this issue Feb 18, 2022 · 8 comments
Open
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway documentation This is a problem with documentation. effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@hoagsie
Copy link

hoagsie commented Feb 18, 2022

link to reference doc page

https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html

Describe your issue?

Similar Issues

#6804
#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, Zone Z1UJRXOUMOOFQ8 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. Executing aws apigateway get-domain-name does not reveal what the alias target is. Trying to query the Route 53 service with the Z1UJRXOUMOOFQ8 zone ID naturally results in an AccessDenied error.

@hoagsie hoagsie added documentation This is a problem with documentation. feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Feb 18, 2022
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Feb 18, 2022
@behr-davide
Copy link

behr-davide commented Feb 24, 2022

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

@zomgbre
Copy link

zomgbre commented Mar 24, 2022

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.

@gazal-k
Copy link

gazal-k commented May 7, 2022

#4887 (comment) helped

This works:

	new CfnBasePathMapping(this, 'basePath', {
			domainName: 'example.com',
			basePath: 'basePath',
			restApiId: restApiId,
			stage: 'prod',
		});

As suggested in #6804 & #4887 (comment), 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

@peterwoodworth
Copy link
Contributor

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.

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 3, 2022
@otaviomacedo otaviomacedo removed their assignment Jun 27, 2022
@davideicardi
Copy link

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

@flexelem
Copy link
Contributor

flexelem commented Mar 21, 2023

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.

@dguisinger
Copy link

@davideicardi I have replicated what you did as well, it works great. I agree, those fields should be optional.

@BwL1289
Copy link

BwL1289 commented Mar 3, 2024

Also see #13725 and #3103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway documentation This is a problem with documentation. effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

10 participants