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

AWS Lambda layers defined on the service level are not merged with layers defined per each function #11063

Open
4 tasks done
dimitor115 opened this issue May 11, 2022 · 6 comments · May be fixed by #12331
Open
4 tasks done

Comments

@dimitor115
Copy link

Are you certain it's a bug?

  • Yes, it looks like a bug

Is the issue caused by a plugin?

  • It is not a plugin issue

Are you using the latest version?

  • Yes, I'm using the latest version

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Issue description

According to the serverless framework documentation, there is an option to define the Lambda Layer on the service level as well as on the single function level: docs. I'm expecting the list of layers defined "globally" should be merged with the list of layers defined on each function layer.

After running the serverless package command with the service configuration defined below, the Cloud Formation template in the HelloLambdaFunction resource definition contains only the layer defined on the function layer, while it should have both.

This overriding behaviour is very annoying, especially when using plugins like serverless-plugin-lambda-insights. This one is adding a LambdaInsights layer to each handler, so I'm unable to define a global layer for all my handlers in the service.

Service configuration (serverless.yml) content

service: layers-bug-reproduction

frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs14.x
  layers: 
    - arn:aws:lambda:us-east-1:580247275435:layer:xxx:1

functions:
  hello:
    handler: handler.hello
    layers: 
      - arn:aws:lambda:us-east-1:580247275435:layer:xxx:2

Command name and used flags

serverless package

Command output

Packaging layers-bug-reproduction for stage dev (us-east-1)

✔ Service packaged (0s)

Environment information

Framework Core: 3.17.0
Plugin: 6.2.2
SDK: 4.3.2
@pgrzesik
Copy link
Contributor

Hey @dimitor115 - thanks a lot for reporting and sorry you've run into trouble. I've verified and managed to replicate this behavior - I agree that it's quite surprising and might be potentially a bug, however, we need to be careful with the potential change here, as it would be a breaking change for people that might depend on current behavior. I will bring up the. issue internally and report back.

@mnapoli
Copy link
Contributor

mnapoli commented May 17, 2022

Given this is a breaking change I don't see how we can change that in v3.

For comparison, do environment, tags and package override or extend?

@pgrzesik
Copy link
Contributor

pgrzesik commented May 17, 2022

Hey @dimitor115 - just for clarification - this is not preventing specific settings but creates inconvenience, where in some cases you need to repeat certain layers for each function instead of specifying it once at the provider level? After thinking about it more, I think there are reasons for both override and extend behavior when having layers defined on the provider and on function level.

@dimitor115
Copy link
Author

@pgrzesik Hey, you are right the current behaviour does not prevent me from configuring the layers as needed, however, it is super painful in my case, because I would need to add it manually to around 150 handlers. Of course, I understand that it would be a breaking change and because of that, you won't change it soon (if even), however, I think the current behaviour should be explicitly described in the documentation :)

@pgrzesik
Copy link
Contributor

I totally agree with that @dimitor115.

If anyone would be interested in submitting a PR with clarification in docs, we'd be more than happy to accept it 🙌

@junwen-k
Copy link

I've updated the docs, feel free to take a look :)

Regarding to the issue, perhaps we could make overriding to be the default behaviour and add an option (perhaps a config in serverless.yml) that will instead merge the layers.

provider:
  ...
  mergeLayers: true # Maybe on global level, for example

However, merging them might exceed the 5 layers limit. E.g, 3 layers on the service level, and 3 layers in the function level. Not sure if this is is an issue or not though, Cloudformation might just block the update if it detects more than 5 layers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants