Sharing Lambda layers across stack fails with error: Export EXPORT_NAME cannot be updated as it is in use by STACK_1, STACK_N
See original GitHub issue- Stack 1 has reached the limit of 500 resources per stack, so I decided to create some additional stacks and share the API between them.
export default class Stack2 extends sst.Stack {
constructor(scope: sst.App, id: string, props: StackProps) {
super(scope, id, props);
props.api.addRoutes(this, {
...testRoutes,
...otherTestRoutes,
});
}
}
- Stack1 has a common PrismaLayer
layers: [
new lambda.LayerVersion(stack, 'PrismaLayer', {
code: lambda.Code.fromAsset('./lambda-layers-prisma-client'),
}),
],
- When I try to deploy the updates, I have got an error
Stack1 failed: Export Stack1:ExportsOutputRefPrismaLayer958161C6A54DA9DC cannot be updated as it is in use by Stack2 and Stack3
Currently, I can remove Stack2 and Stack3 manually and then update the App, is there another way how to fix the error?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Sharing Lambda layers across stack fails with error: Export ...
Sharing Lambda layers across stack fails with error: Export EXPORT_NAME cannot be updated as it is in use by STACK_1, STACK_N #549.
Read more >Resolve the "Export EXPORT_NAME cannot be updated as it ...
You get this error when one or more stacks are importing an exported output value from the stack that you want to update...
Read more >How to fix AWS CDK error: “Export [export name] cannot be ...
First, figure out which stack is using the exported value. You can use the AWS CLI or AWS CloudFormation console to find this....
Read more >Update Cross-Stack AWS Lambda Layers - GnomezGrave
So, you put all these dependencies into a Lambda Layer and import them (using Exports and Imports) to your Lambda functions.
Read more >How to use AWS Lambda Layers with SAM - BlowStack
“When working with a nested SAM stack, you cannot import a Lambda Layer exported from another stack.” But it's not true. You can...
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
No results found
Top Related Hashnode Post
No results found
@fwang Does this fix only use SSM when adding layers to each function individually? I was using addDefaultFunctionLayers and noticed it defaulted back to using stack exports. It would be great if we could use addDefaultFunctionLayers and not have the dependency issue.
Hey @pabacham, here’s what I found.
What is the issue?
The Lambda layer is created in stack 1 and shared in stack 2. When you share a layer across stacks, CDK creates a stack export with the layer’s ARN in stack 1. And everytime the layer changes (ie. when you run codegen), the layer’s ARN changes (ie. the ARN always ends with a number). However, CloudFormation does not allow updating exported values. You can read more about this CDK issue here - https://github.com/aws/aws-cdk/issues/1972
How are we going to fix it?
Like mentioned in the above thread, when SST detects a Lambda layer is shared across stacks, it will create an SSM parameter in stack 1 with the layer’s ARN. And stack 2 will reference the SSM value, instead of the ARN directly.
I’m working on a fix for this rn.