Search code examples
typescriptaws-api-gatewayaws-cdkapi-gateway

Accessing the AWS gateway resource in another stack in cdk stack


I have a stack where an api gateway resource is created. I have a construct under this stack from where i need to create a method to the above resource. I tried passing the resource as the props to the construct. But it throws error as

throw new Error(${construct.constructor?.name ?? 'Construct'} at '${Node.of(construct).path}' should be created in the scope of a Stack, but no Stack found);

Any idea on creating and passing the aws api gateway resource inside a stack and pass it to the construct or another stack.


Solution

  • The issue is with the scope that is used to create the construct. Changed the scope of the construct to this then it worked fine.