-
Notifications
You must be signed in to change notification settings - Fork 4k
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
A RestApi and RequestAuthorizer in separate projects throws an error #7377
Comments
It looks like this line in lib/method.ts that calls If I munge the resulting javascript in my node_modules directory, I can get // if (authorizer instanceof authorizer_1.Authorizer) {
if (authorizer instanceof Object && typeof authorizer._attachToApi === 'function') {
authorizer._attachToApi(this.restApi);
} |
@pofallon - can you check if both of your libraries are using the same version of the CDK packages during typescript compilation of each of them? The |
Hello! Thanks for following up. I double-checked and confirmed they're running the same version:
(I've updated the libraries locally since filing the ticket, to see if it was still a problem -- it is.) |
Or two different instances of the same version... If the library is installed at two different points in the runtime closure (aka it is present more than once in the output of |
I am able to reproduce this issue. @RomainMuller - unfortunately that doesn't seem to be the issue. Exactly one instance of the module is installed in node tree. ⇒ npm ls | grep apigateway
├─┬ @aws-cdk/aws-apigateway@1.32.2 ⇒ tree node_modules | grep aws-apigateway
│ ├── aws-apigateway |
The setting up of this project involves using You can easily verify this by issuing This is a quirk of how I guess this is one more reason to avoid using |
Thanks @RomainMuller for the lead. Confirmed that the problem was that there were two instances of the |
When an Authorizer is defined in one node project, imported into another where it is wired up with a RestApi, synthesis throws the error 'Authorizer must be attached to a RestApi'. The root cause of this error is the `instanceof` check. If a user has their project set up in a way that more than one instance of the `@aws-cdk/aws-apigateway` module is present in their `node_modules/` folder, even if they are of the exact same version, type checking is bound to fail. Switching instead to a symbol property based comparison, so that type information survives across installations of the module. fixes #7377
When an Authorizer is defined in one node project, imported into another where it is wired up with a RestApi, synthesis throws the error 'Authorizer must be attached to a RestApi'. The root cause of this error is the `instanceof` check. If a user has their project set up in a way that more than one instance of the `@aws-cdk/aws-apigateway` module is present in their `node_modules/` folder, even if they are of the exact same version, type checking is bound to fail. Switching instead to a symbol property based comparison, so that type information survives across installations of the module. fixes #7377
#7596) When an Authorizer is defined in one node project, imported into another where it is wired up with a RestApi, synthesis throws the error 'Authorizer must be attached to a RestApi'. The root cause of this error is the `instanceof` check. If a user has their project set up in a way that more than one instance of the `@aws-cdk/aws-apigateway` module is present in their `node_modules/` folder, even if they are of the exact same version, type checking is bound to fail. Switching instead to a symbol property based comparison, so that type information survives across installations of the module. fixes #7377
Thanks so much for the fix - I really appreciate it! |
I have a project (see reproducible sample below) where an API Gateway RestApi is defined in a CDK stack and passed as a property to a CDK library. In this library a RequestAuthorizer is defined and attached to a method on the RestApi. This process works when the RestApi and RequestAuthorizer are two TypeScript modules in the same project. However, when they are in separate projects,
cdk synth
fails with anAuthorizer (...) must be attached to a RestApi.
error.Reproduction Steps
This example project has code and steps to reproduce the error. In short:
cdk synth
and see the errorError Log
Environment
Other
Stack trace:
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: