awslabs / serverless-plugin-lambda-insights

MIT No Attribution
45 stars 16 forks source link

Plugin does not recognize service level layer #27

Open kenhks opened 2 years ago

kenhks commented 2 years ago

Version Info Serverless: 3.18.1 Serverless-plugin-lambda-insights: 1.5.0

# serverless.yml
provider:
  name: aws
  ...
  layers:
    - layer1ARN

functions:
  func1:
    ...
   # no function level layer

plugins:
  - serverless-plugin-lambda-insights

Expected Outcome: func1 has two layers, layer1 and LambdaInsightsExtension

Actual Result: func1 has only one layer LambdaInsightsExtension

nicemaker commented 2 years ago

The issues above I managed to workaround by just adding the layer to each function, like:

functions:
  myFun:
    handler: src/serverless.myFun
    layers:
      - {MyLayerArn}

Would be great though to be able to be able to add my layer only on provider level and done. And, very important, I think this issue also creates conflicts with other plugins, in my case serverless-layers, see config below, serverless layers doesn't really need any configuration. As soon as I remove lambda insights its working as expected:

plugins:
  modules:
    - serverless-plugin-lambda-insights
    - serverless-layers

    ....
custom:
  lambdaInsights:
     defaultLambdaInsights: true
tibbe commented 2 years ago

Ran into the same problem today. If you use any other layers, for example through the serverless-python-requirements plugin (which I expect just about any Python project to use), you run into this problem.

The workaround is also quite inconvenient as you need to do something for every new lambda function you add.

tibbe commented 2 years ago

What probably should happen is that instead of adding the layer to each function when defaultLambdaInsights: true:

https://github.com/awslabs/serverless-plugin-lambda-insights/blob/470831dcc59b3cfd1ab3a63a8f84fa1f5416ee68/index.js#L214

Add it to the provider section layers.

mhouchin commented 1 year ago

We're also experiencing this issue when our own defined layers are not being attached, as the lambda insights layer overrides any existing layers attached.