question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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
  1. 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,
    });
  }
}
  1. Stack1 has a common PrismaLayer
layers: [
      new lambda.LayerVersion(stack, 'PrismaLayer', {
        code: lambda.Code.fromAsset('./lambda-layers-prisma-client'),
      }),
    ],
  1. 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:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Morriphicommented, Feb 22, 2022

@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.

1reaction
fwangcommented, Jul 22, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found