Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pabacham opened this issue Jul 14, 2021 · 9 comments · Fixed by #590
Labels
bug Something isn't working
Projects

Comments

@pabacham
Copy link

  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?

@fwang
Copy link
Contributor

fwang commented Jul 14, 2021

Hey @pabacham, do you get this error when you try to deploy after changing the layer? And can you share the stack export values from stack 1?

@pabacham
Copy link
Author

@fwang

  1. Yes. Before every deployment, I run "prisma generate" command and then put it as a layer. The idea was taken from here https://dev.to/eddeee888/how-to-deploy-prisma-in-aws-lambda-with-serverless-1m76
  2. The only exported value is API. this.api = api; https://monosnap.com/file/Hlh5uTIKpAE4vs7YcIQt6CwCD2kh1t

а) props.api.addLayers method could potentially help me
b) another way of updating and deploying Prisma

@fwang
Copy link
Contributor

fwang commented Jul 16, 2021

@pabacham, when you are sharing a layer across stack, I think the layer's ARN is automatically added as a stack export. If you go to your CFN console, find stack 1, and look at its export values, you should see it there.

Let's just confirm that is the issue.

@pabacham
Copy link
Author

@fwang
Copy link
Contributor

fwang commented Jul 21, 2021

Thanks @pabacham, does the output value for the Prisma layer end with a version number?

@fwang fwang added the bug Something isn't working label Jul 21, 2021
@fwang fwang added this to Priority: High in Roadmap Old Jul 21, 2021
@pabacham
Copy link
Author

@fwang

Stack 1
Status: deployed
Outputs:
ExportsOutputRefPrismaLayer958161C6A54DA9DC: arn:aws:lambda:us-east-1:660857977215:layer:PrismaLayer958161C6:53

Let me know if you mean smth other than that

@fwang
Copy link
Contributor

fwang commented 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 - aws/aws-cdk#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.

@fwang fwang moved this from Priority: High to In Progress in Roadmap Old Jul 22, 2021
@fwang fwang changed the title Error: Export EXPORT_NAME cannot be updated as it is in use by STACK_1, STACK_N Sharing Lambda layers across stack fails with error: Export EXPORT_NAME cannot be updated as it is in use by STACK_1, STACK_N Jul 22, 2021
@fwang
Copy link
Contributor

fwang commented Jul 23, 2021

@pabacham Fixed in v0.35.1. Give it a try!

@Morriphi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Roadmap Old
In Progress
Development

Successfully merging a pull request may close this issue.

3 participants