AWS Lambda Support
SeaLights provides a simple way to collect code coverage from AWS Lambda functions using a lightweight Lambda Layer for Node.js runtimes. The integration requires minimal changes to your deployment and no changes to your application code.
To use SeaLights with AWS Lambda, you’ll:
Add the SeaLights Layer to your function.
Set a few required environment variables.
Ensure your SeaLights collector is configured to accept coverage from Lambda executions.
Prerequisites
Before starting, make sure:
Node.js version 16.20.2 or higher.
AWS Lambda using a supported Node.js runtime (e.g.,
nodejs16.x,nodejs18.x).AWS CLI or Serverless Framework access to modify function deployment.
SeaLights agent token and buildsession ID.
Important: When scanning your code using slnodejs scan, you must add the --awsConfigure flag to ensure proper Lambda support.
Configuration
Step 1: Add the SeaLights Lambda Layer
In your deployment manifest (serverless.yml or AWS config), add the following layer to each function or define it globally:
yamlCopyEdit# At the function level
functions:
myLambda:
handler: src/myLambda.handler
layers:
- arn:aws:lambda:eu-west-1:159616352881:layer:sl-nodejs-layer:44Or define it globally:
yamlCopyEditprovider:
layers:
- arn:aws:lambda:eu-west-1:159616352881:layer:sl-nodejs-layer:44Step 2: Set Environment Variables
Configure the following environment variables for each function that should report coverage:
yamlCopyEditenvironment:
AWS_LAMBDA_EXEC_WRAPPER: /opt/sealights-extension
SL_TOKEN: your-sl-token
SL_BUILD_SESSION_ID: your-build-session-id
SL_PROJECT_ROOT: ./src
LAB_ID: lambda-testThese variables are used by the SeaLights agent to identify your function and store coverage data. The AWS_LAMBDA_EXEC_WRAPPER is required to enable the layer functionality.
Step 4: Verify the Setup in the SeaLights Cockpit
Once your Lambda function is deployed and invoked:
You should see two entries in the Live Agents Monitor in the SeaLights Cockpit:
The Application (your Lambda function)
The Collector reporting the coverage
If both are visible, your setup is complete, and data collection has started successfully.
How It Works
When a Lambda function is instrumented with the SeaLights agent, the SeaLights Lambda Layer wraps the original handler and collects coverage during its execution. The process is seamless and transparent to your function code.

The sequence works as follows:
SeaLights Layer is invoked first: AWS uses the
AWS_LAMBDA_EXEC_WRAPPERto redirect the function call.Coverage starts before your original handler is called.
The original Lambda function runs as usual.
When your function completes, coverage is stopped and converted into a footprint.
The footprint is sent to the SeaLights collector, and the original response is returned.
You can see this flow in the diagram below:

This design ensures accurate, real-time coverage data with minimal impact on performance or function logic.
Additional Notes
Working with Other Lambda Layers
SeaLights is compatible with third-party Lambda observability layers:
Dynatrace
/opt/dynatrace
Supported automatically
OTEL
/opt/otel-handler
Supported automatically
To explicitly disable integration with OTEL or Dynatrace:
yamlCopyEditenvironment:
DISABLE_OTEL_HANDLER: true
DISABLE_DYNATRACE: trueTroubleshooting
Make sure
AWS_LAMBDA_EXEC_WRAPPERis set correctly.Ensure the layer ARN is present in the function configuration.
Verify your
SL_TOKEN,SL_BUILD_SESSION_ID, andSL_PROJECT_ROOTare set and correct.The function must run at least once to appear in the Live Agents Monitor.
Example Project
You can review a working Serverless Framework example here: https://github.com/Sealights/SL.OnPremise.Lambda.Layers/tree/master/node/example
It includes a basic function and pre-configured settings for SeaLights Lambda integration.
Last updated
Was this helpful?

