Description
The Lambda Insights plugin only runs during full stack deployments (sls deploy) but not during single function deployments (sls deploy function -f functionName). This means functions deployed individually don't get the Lambda Insights layer attached, even when defaultLambdaInsights: true is configured globally.
Configuration
custom:
lambdaInsights:
defaultLambdaInsights: true
Expected Behavior
When running sls deploy function -f myFunction, the Lambda Insights layer should be added to the function, just like it would during a full sls deploy.
Actual Behavior
sls deploy: ✅ Lambda Insights layer is added correctly
sls deploy function -f myFunction: ❌ Lambda Insights layer is NOT added
Root Cause
The plugin only hooks into before:package:setupProviderConfiguration, which is part of the full deployment lifecycle. Single function deployments use a different lifecycle (deploy:function:* hooks) that doesn't include this hook.
Reproduction Steps
- Configure
defaultLambdaInsights: true in serverless.yml
- Run
sls deploy - verify function has Lambda Insights layer in AWS Console
- Make a code change to a single function
- Run
sls deploy function -f myFunction
- Check AWS Console - Lambda Insights layer is missing
Suggested Fix
Add the before:deploy:function:packageFunction hook to handle single function deployments:
this.hooks = {
'before:package:setupProviderConfiguration': this.addLambdaInsights.bind(this),
'before:deploy:function:packageFunction': this.addLambdaInsights.bind(this), // Add this
};
Environment
- Serverless Framework: 3.x
- Plugin version: 1.6.0
- Node.js version: 20.x
Workaround
Currently, users must run a full sls deploy instead of sls deploy function to ensure Lambda Insights layer is present.
Description
The Lambda Insights plugin only runs during full stack deployments (
sls deploy) but not during single function deployments (sls deploy function -f functionName). This means functions deployed individually don't get the Lambda Insights layer attached, even whendefaultLambdaInsights: trueis configured globally.Configuration
Expected Behavior
When running
sls deploy function -f myFunction, the Lambda Insights layer should be added to the function, just like it would during a fullsls deploy.Actual Behavior
sls deploy: ✅ Lambda Insights layer is added correctlysls deploy function -f myFunction: ❌ Lambda Insights layer is NOT addedRoot Cause
The plugin only hooks into
before:package:setupProviderConfiguration, which is part of the full deployment lifecycle. Single function deployments use a different lifecycle (deploy:function:*hooks) that doesn't include this hook.Reproduction Steps
defaultLambdaInsights: truein serverless.ymlsls deploy- verify function has Lambda Insights layer in AWS Consolesls deploy function -f myFunctionSuggested Fix
Add the
before:deploy:function:packageFunctionhook to handle single function deployments:Environment
Workaround
Currently, users must run a full
sls deployinstead ofsls deploy functionto ensure Lambda Insights layer is present.