APIGateway and Lambdas in separate stacks fails
See original GitHub issue🐛 Bug Report
What is the problem?
I have what I would expect a very typical scenario: APIGateway that exposes several of my lambdas. I frequently have to delete the whole stack and would like to avoid destroying the APIGateway (so as not to change the URL and apikeys). So I wanted to split them to two stacks, one for the APIGateway and one for Lambdas. I first tried with CDK 1.1.0. This caused cyclic dependency errors (which I mentioned here. In hopes of it being fixed, I upgraded to 1.4.0. Now with the same setup I get:
cfn-reference.ts:108
throw new Error(`Cross-stack reference (${context.scope.node.path} -> ${this.target.node.path}) has not been assigned a value--call prepare() first`);
^
Error: Resolution error: Resolution error: Resolution error: Cross-stack reference (ipk-PostiKioskiBackendStack-development -> ipk-PostiKioskiLambdaStack-development/ipk-ConfigLambda-development/Resource) has not been assigned a value--call prepare() first.
Object creation stack:
at new Intrinsic (/Users/vertti/dev/posti/itsepalvelu-posti/posti-kioski-backend/node_modules/@aws-cdk/core/lib/private/intrinsic.ts:28:26)
at new Reference (/Users/vertti/dev/posti/itsepalvelu-posti/posti-kioski-backend/node_modules/@aws-cdk/core/lib/reference.ts:21:5)
Reproduction Steps
Backend defined with:
const app = new core.App()
const stackLambda = new PostiKioskiLambdaStack(app, `ipk-PostiKioskiLambdaStack-${environment}`)
const stackBE = new PostiKioskiBackendStack(app, `ipk-PostiKioskiBackendStack-${environment}`, { configLambda: stackLambda.configLambda })
where PostiKioskiLambdaStack
creates a lambda to a public configLambda
property which is given in the props to stackBE
.
The lambda in question is put inside a specific vpc:
this.configLambda = new awsLambda.Function(this, `ipk-ConfigLambda-${environment}`, {
role,
vpc,
code: awsLambda.Code.asset('resources'),
handler: 'config_lambda.handler',
runtime: awsLambda.Runtime.NODEJS_10_X,
})
Verbose Log
https://gist.github.com/vertti/4883548b587774d1f1d2a75e78b640a1
Environment
- CDK CLI Version: 1.4.0 (build 175471f)
- OS: OSX Mojave
- Language: TypeScript
Other information
There’s been lots of fixes done for similar cases where Lambdas are in one stack and for example SNS is in another, all of those seemed to cause cyclic dependency errors.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top GitHub Comments
Update: Identified that the bug lies with API Gateway specific implementation of the Prepare phase, specifically within the
LatestDeploymentResource
.The bug is here - https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-apigateway/lib/deployment.ts#L131.
The prepare phase, among other things, identifies intra-stack and cross-stack dependencies and registers them, for future resolution. It can be fully resolved only after the prepare phase is complete.
Able to reproduce this with this CDK code -
followed by running
cdk synth