Integrating Thundra using AWS Lambda Layers is the recommended (and easier) way to get started with Thundra. Depending on whether or not you choose to use a custom runtime, you can integrate Thundra with no code changes at all or just by wrapping your handler function.
Bundle all your Node.js Lambda function files and any additional required packages, and then upload it to the AWS Lambda console using the “Upload a.zip file” option for the code entry type. Note that Thundra dependencies are not expected to be in the artifact to be uploaded, as they come with a layer that will be utilized at a later point.
Add Thundra's Node.js layer to your Lambda function using the ARN below. Note that the ARN contains a region and a version parameter which you will need to set. Set the region value to your Lambda function's region and the version value to the layer version you want to use with your Lambda function.
arn:aws:lambda:${region}:269863060030:layer:thundra-lambda-node-layer-minified:${version}
After the Thundra layer ARN has been added, you can continue using a custom runtime or continue without using a custom runtime. Regardless of what you choose, make sure to also set the thundra_apiKey environment variable to the API key you get from the Thundra console.

Set the handler to thundra_handler.wrapper and then set the thundra_agent_lambda_handler environment variable value to your original handler (e.g., index.handler).
You can wrap your Lambda handler to integrate Thundra as shown below.
index.jsconst thundra = require("@thundra/core")();exports.handler = thundra((event, context,callback) => {callback(null, "Hello Thundra!");});
In the example above, the required @thundra/core package is already available in Thundra's Node.js layer, which we already added. Thus, you don't need to install the package and bundle it with your Lambda function.
Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!
If you do not want to use AWS Lambda Layers, you can still easily integrate Thundra to your Node.js Lambda function. All you have to do is install the @thundra/core package via npm.
npm install @thundra/core --save
After installing the @thundra/core module, you will need to wrap your Lambda handlers. Thundra will monitor your AWS Lambda function automatically, supporting callback along with various context functions.
handler.jsconst thundra = require("@thundra/core")();exports.handler = thundra((event, context,callback) => {callback(null, "Hello Thundra!");});
Bundle your function and any additional required Node.js packages, and then upload it to the AWS Lambda console using the “Upload a.zip file” option for the code entry type.
In the AWS Lambda console, set the thundra_apiKey environment variable to the API key value you got from the Thundra console.

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!
npm install serverless-plugin-thundra
After installing Thundra’s serverless plugin, specify it as a plugin for your serverless environment by adding it under the plugins section of your serverless.yml file.
serverless.ymlplugins:- serverless-plugin-thundra
Step 3: Add thundra_apiKey to Environment Variables under Provider Section in serverless.yml
serverless.ymlprovider:environment:thundra_apiKey: <YOUR THUNDRA API KEY>
Step 4: Deploy
serverless deploy
Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!
Add the thundra_apiKey environment variable using your Thundra API key.
Globals:Function:Environment:Variables:thundra_apiKey: <your_api_key>
Add the Thundra layer to “Layers” in the Globals section. The ThundraAWSAccountNo and ThundraPythonLayerVersion parameters are defined in the Parameters section in the following configuration:
Latest version of the Thundra's Node.js layer:
Parameters:ThundraAWSAccountNo:Type: NumberDefault: 269863060030ThundraNodeLayerVersion:Type: NumberDefault: 24 # Or use any other versionGlobals:Function:Layers:- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-node-layer:${ThundraNodeLayerVersion}…
Change Runtime of your functions to provided
Resources:HelloWorldFunction:Type: AWS::Serverless::FunctionProperties:Runtime: providedHandler: handler.hello
An example configuration:
Parameters:ThundraAWSAccountNo:Type: NumberDefault: 269863060030ThundraNodeLayerVersion:Type: NumberDefault: 24 # Or use any other versionGlobals:Function:Runtime: providedTimeout: 5Environment:Variables:thundra_apiKey: <your_api_key>Layers:- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-node-layer:${ThundraNodeLayerVersion}Resources:HelloWorldFunction:Type: AWS::Serverless::FunctionProperties:CodeUri: ./Handler: handler.hello
Step 2: Test / Deploy
To build and run your function locally, use the following:
sam build && sam local invoke
Then, package and deploy your function using sam.
Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!
Add thundra_apiKey environment variable with your thundra API key.
import {Function} from "@aws-cdk/aws-lambda";export class YourConstructClass extends core.Construct {const thundraApiKey = <your_api_key>;constructor(scope: core.Construct, id: string) {const yourFunction = new Function(this, "YourHandler", {..., // other function propertiesenvironment: {..., // other environment variablesthundra_apiKey: thundraApiKey}});}}
Define Thundra layer and add it to your function properties.
Latest version of the Thundra's Node.js layer:
import {Aws} from "@aws-cdk/core";import {Function, LayerVersion} from "@aws-cdk/aws-lambda";export class YourConstructClass extends core.Construct {const thundraApiKey = <your_api_key>;const thundraAWSAccountNo = 269863060030;const thundraNodeLayerVersion = 48; // or any other versionconst thundraLayer = LayerVersion.fromLayerVersionArn(this,"ThundraLayer",`arn:aws:lambda:${Aws.REGION}:${thundraAWSAccountNo}:layer:thundra-lambda-node-layer:${thundraNodeLayerVersion}`);constructor(scope: core.Construct, id: string) {const yourFunction = new Function(<scope>, <id>, {..., // other function propertiesenvironment: {..., // other environment variablesthundra_apiKey: thundraApiKey},layers: [thundraLayer,... // other layers]});}}
Aws.REGION is a pseudo parameter which is bootstrapped from your stack's environment configuration
Change Runtime of your function to provided
import {Function, LayerVersion, Runtime} from "@aws-cdk/aws-lambda";import {Aws} from "@aws-cdk/core";import {Function, LayerVersion} from "@aws-cdk/aws-lambda";export class YourConstructClass extends core.Construct {const thundraApiKey = <your_api_key>;const thundraAWSAccountNo = 269863060030;const thundraNodeLayerVersion = 48; // or any other versionconst thundraLayer = LayerVersion.fromLayerVersionArn(this,"ThundraLayer",`arn:aws:lambda:${Aws.REGION}:${thundraAWSAccountNo}:layer:thundra-lambda-node-layer:${thundraNodeLayerVersion}`);constructor(scope: core.Construct, id: string) {const yourFunction = new Function(this, "YourFunction", {..., // other function propertiesruntime: Runtime.PROVIDED,environment: {..., // other environment variablesthundra_apiKey: thundraApiKey},layers: [thundraLayer,... // other layers]});}}
An example configuration:
import {Aws} from "@aws-cdk/core";import {Code, Function, Runtime, LayerVersion} from "@aws-cdk/aws-lambda";export class YourConstructClass extends core.Construct {const thundraApiKey = <your_api_key>;const thundraAWSAccountNo = 269863060030;const thundraNodeLayerVersion = 48; // or any other versionconst thundraLayer = LayerVersion.fromLayerVersionArn(this,"ThundraLayer",`arn:aws:lambda:${Aws.REGION}:${thundraAWSAccountNo}:layer:thundra-lambda-node-layer:${thundraNodeLayerVersion}`);constructor(scope: core.Construct, id: string) {const handler = new Function(this, "MyFunction", {runtime: Runtime.PROVIDED,code: Code.asset("/path/to/your/resource"),handler: "your.handler",environment: {thundra_apiKey: thundraApiKey},layers: [thundraLayer]});}}
npm run build && cdk deploy
Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!