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

APIGateway Type Error "addBasePathMapping is not a function" #7787

Closed
baer opened this issue May 5, 2020 · 6 comments
Closed

APIGateway Type Error "addBasePathMapping is not a function" #7787

baer opened this issue May 5, 2020 · 6 comments
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway docs/inline Related to inline documentation of the API Reference

Comments

@baer
Copy link
Contributor

baer commented May 5, 2020

DomainName.fromDomainNameAttributes created an object that does not have the method addBasePathMapping. This appears to be because the fromDomainNameAttributes returns a stripped-down version of IDomainName, not the full-fledged one you would get from a DomainName created in the CDK stack.

This may be intentional, or a missing feature in the construct but the docs for BasePathMapping say that "In most cases, you will probably want to use DomainName.addBasePathMapping() to define mappings" so it's not something I was expecting. If the intention is that CDK functions *.from<AWS Service>Attributes like this one or the one defined in VPC read-only, that should be a bit more clear in the docs if possible.

Reproduction Steps

const { DomainName } = require(`@aws-cdk/aws-apigateway`);

const myDomain = DomainName.fromDomainNameAttributes(
  this,
  `myDomainResource`,
  { domainName: CERTIFICATE_URL }
);
myDomain.addBasePathMapping(excelProxyApi, {});

Error Log

/some/path/index.js:79
  myDomain.addBasePathMapping(excelProxyApi, {
                   ^
TypeError: excelProxyDomain.addBasePathMapping is not a function

Environment

  • **CLI Version :2.0.9
  • **Framework Version:1.36.1
  • **OS :OSX
  • **Language :JavaScript

Other

Some of the comments in this thread seem to be from other people who are confused by the same problem. #3103


This is 🐛 Bug Report

@baer baer added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 5, 2020
@SomayaB SomayaB added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label May 5, 2020
@nija-at
Copy link
Contributor

nija-at commented May 13, 2020

This API is not supported on imported DomainName. Instead you can use the constructor for BasePathMapping to achieve this.

The 'most cases' in the docs probably refers to when the domain is created is defined as part of the CDK app, and not imported.

@nija-at nija-at added the closing-soon This issue will automatically close in 4 days unless further comments are made. label May 13, 2020
@baer
Copy link
Contributor Author

baer commented May 13, 2020

@nija-at The reason for using one of CDK's *.from<AWS Service>Attributes is because I do not have the option of building it from inside of CDK. There are a number of reasons for this, such as:

  • An "infrastructure stack" created a service that an "application stack" is using
  • The service was created before CDK was brought into the organization
  • You've acquired a team/project/company who has preexisting services
  • etc.

CloudFormation recently launched the ability to import existing resources into a CloudFormation stack, CDK does not support this at the time of writing and *.from<AWS Service>Attributes is the next-best option. I'm only suggesting that some clarity in communication might help folks.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label May 13, 2020
@nija-at
Copy link
Contributor

nija-at commented May 15, 2020

Thanks for the clarification @baer. I believe you are able to use the BasePathMapping constructor for all these use cases. Perhaps dropping that entire statement there would help.

@nija-at nija-at added docs/inline Related to inline documentation of the API Reference and removed bug This issue is a bug. labels May 15, 2020
@nija-at
Copy link
Contributor

nija-at commented May 15, 2020

Are you able to submit a PR to us with some better phrasing here?

@nija-at nija-at removed the needs-triage This issue or PR still needs to be triaged. label May 15, 2020
@baer
Copy link
Contributor Author

baer commented May 15, 2020

You're correct that the BasePathMapping constructor will work for these cases. I created a PR to suggest addBasePathMapping only if they're not importing the Domain

#8017

@nija-at
Copy link
Contributor

nija-at commented May 22, 2020

Resolving since we got the doc updates in - #8017.

@nija-at nija-at closed this as completed May 22, 2020
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 docs/inline Related to inline documentation of the API Reference
Projects
None yet
Development

No branches or pull requests

3 participants