awslabs / awslabs/serverless-plugin-lambda-insights

Lambda Insights layer not added for single function deployments

Open
#53 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
43
Forks
18
PR merge metrics
No merged PRs in 30d

Description

## 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
```yaml
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
1. Configure `defaultLambdaInsights: true` in serverless.yml
2. Run `sls deploy` - verify function has Lambda Insights layer in AWS Console
3. Make a code change to a single function
4. Run `sls deploy function -f myFunction`
5. Check AWS Console - Lambda Insights layer is missing

## Suggested Fix
Add the `before:deploy:function:packageFunction` hook to handle single function deployments:

```javascript
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.