Lightrun for Serverless Functions¶
To run a Serverless function with the Lightrun Node.js agent, follow these steps:
- Ensure that the Lightrun agent has been configured to work with your serverless function. For example, to use Lightrun with an AWS Lambda function, you must first package the Lightrun agent into an AWS Lambda Layer. Follow the instructions here to set up a lambda layer for your Lightrun Node.js agent.
- Import the Lightrun serverless module in your serverless function code.
const lightrun = require('lightrun/lambda').start({ lightrunSecret: 'aaaaaa-bbbb-cccc-dddd-eeeeeeeeeee' });
- Wrap your serverless function handler with the Lightrun serverless module.
function handler(event, context, callback) { callback(null, "Hello World"); } exports.handler = lightrun.wrap(handler);
Note
The Lightrun serverless module wraps around your serverless function and ensures that the Lightrun agent is enabled before calling the serverless function. It also disables the Lightrun agent when the function call finishes so that it can properly handle the next call to the serverless function.
Last update: March 16, 2023