[lambda] deployment failure on updates to cross-stack layers
See original GitHub issueHere is the application structure:
- Stack A:
- lambda layer
- Stack B: Depends on A:
- Lambda which is using the layer
new lambda.Function(this, 'some-lambda'
{
...
layers: [stackA.lambdaLayer]
}
)
where stackA.lambdaLayer
is an instance of lambda.LayerVersion
.
The initial deployment works well. However, when the layer code is changed and the second deployment takes place, Stack A deployment fails with error message:
lambdas-layer (…) Requested update requires the creation of a new physical resource; hence creating one. Resource creation Initiated dev-StackA Export dev-CoreStack:corelambdaslayerLayerVersionArn261FB3DB cannot be updated as it is in use by dev-StackB
Issue Analytics
- State:
- Created 5 years ago
- Reactions:34
- Comments:18 (9 by maintainers)
Top Results From Across the Web
Update Cross-Stack AWS Lambda Layers - GnomezGrave
Let's assume we deploy the Lambda layer for the first time. So it's ARN will have :1 at the end denoting the Layer...
Read more >Troubleshoot deployment issues in Lambda
When you update your function, Lambda deploys the change by launching new instances of the function with the updated code or settings. Deployment...
Read more >CDK tips, part 3 – how to unblock cross-stack references
I think the correct way is still to do the change in 2 steps ("Update and reference the new layer in all lambdas....
Read more >b-cfn-lambda-layer 2.4.1 - PyPI
If we do, the next update to the source code in the lambda layer would result in a failed deployment. This is because...
Read more >amazon cloudformation - Updating dependent stacks
When I try to update stack-layer , I get an error: Export layer-arn cannot be deleted as it is in use by stack-lambda...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
@eladb I’ve worked around this by using a SSM parameter store to reference the latest
layerVersionArn
and then accessing the layer instance viaLayer.fromLayerVersionArn()
. (Nod to @rhboyd for this idea.)I wrote a custom construct to act as such a proxy:
I split the layers into a stack of their own, and share the ARN via SSM.Params, to then be used by a lambda in another stack. So no hard dependency…
You can see both the layer creation and then usage (which would usually be in a separate stack)
https://github.com/ranguard/cdk-talk-examples/tree/master/code/lambda_layer_example/lib
We have a ‘layers’ stack
AWS keeps layer versions around, whilst any lambda is pointing at them - so new layer deploys won’t break existing functions - but you do need to re-deploy any stack that is using the layers