Integration Options

Using AWS Lambda Layers
Without using AWS Lambda Layers
Serverless Framework
AWS SAM

Integrating Thundra using the AWS Lambda Layers is the recommended and easier way to get start with Thundra. Depending on your choice to use custom runtime, you can integrate Thundra with no code change at all or just by wrapping your handler function.

Step 1: Deploy your function to AWS Lambda

Bundle all your Node.js lambda function files, along with any additional required packages and upload it to the AWS Lambda console using the 'Upload a.zip file' option for the code entry type option. Note that Thundra dependencies are not expected to be in the artifact to be uploaded as it comes with layer that will be mentioned at later steps.

Step 2: Configure your function

  • Add Thundra's Node.js layer to your Lambda function using the below ARN. Note that the ARN contains a region and a version parameter which you should set correctly. Set region value to your Lambda function's region and version value to the layer version you want to use with your Lambda function.

arn:aws:lambda:${region}:269863060030:layer:thundra-lambda-node-layer:${version}
Latest version of the Thundra Node.js layer
  • After having added the Thundra layer ARN, you can continue using custom runtime or without using the custom runtime. Regardless of you choice make sure to also set thundra_apiKeyenvironment variable to your api key you get from the Thundra console.

Step 3:

a. Using custom runtime

Using the Thundra's custom Node.js runtime, you can integrate Thundra to your Node.js Lambda functions with zero code change. Once you add the Thundra layer as described above, all you have to do is change your Lambda function's runtime to Custom Runtime in the AWS Lambda Console.

If you are using Serverless Framework, you can set your function runtime to provided in you serverless.yml file. This will set your function to use the custom runtime.

b. Without using the custom runtime

If you have added the Thundra's Node.js layer but do not prefer to use custom runtime, you can wrap your Lambda handler to integrate Thundra as below.

handler.js
const thundra = require("@thundra/core")();
exports.handler = thundra((event, context,callback) => {
callback(null, "Hello Thundra!");
});

In the above code example, required @thundra/core package is already available in the Thundra's Node.js layer we have added before. Thus, you don't need to install the package and bundle it with your lambda function.

Step 5: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

Without using AWS Lambda Layers

If you do not want to use AWS Lambda Layers, you can still easily integrate Thundra to your Node.js Lambda functions. All you have to do is installing @thundra/core package via npm.

Step 1: Install the @thundra/core package

npm install @thundra/core --save

Step 2: Wrap your Lambda handler

After installing the thundra/core module, you will need to wrap your lambda handlers. Thundra will monitor your AWS Lambda functions automatically, supporting callback along with various context functions.

handler.js
const thundra = require("@thundra/core")();
exports.handler = thundra((event, context,callback) => {
callback(null, "Hello Thundra!");
});

Step 3: Deploy your function to AWS Lambda

Bundle your function along with any additional required Node.js packages and upload it to the AWS Lambda console using the 'Upload a.zip file' option for the code entry type option.

Step 4: Configure your function

In the AWS Lambda console, set the thundra_apiKey the environment variable to the api key value you got from the Thundra console.

Step 5: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

Serverless Framework

Step 1: Install Thundra’s serverless plugin to automatically wrap your functions

npm install serverless-plugin-thundra

Step 2: Adding Thundra's Serverless Plugin in serverless.yml File After installing Thundra’s serverless plugin, please specify it as a plugin for your serverless environment by adding it under the plugins section of your serverless.yml file.

serverless.yml
plugins:
- serverless-plugin-thundra

Step 3: Add thundra component to custom

Add the thundra component under custom with apiKey under that, as seen below:

serverless.yml
custom:
thundra:
apiKey: <YOUR THUNDRA API KEY>

Step 4: Add thundra_apiKey to environment variables under provider section in serverless.yml

serverless.yml
provider:
environment:
thundra_apiKey: <YOUR THUNDRA API KEY>

Step 5: Deploy

serverless deploy

Step 5: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

AWS SAM

Step 1: Add configuration changes on SAM template.yml

  • Add thundra_apiKey environment variable with your thundra api key.

Globals:
Function:
Environment:
Variables:
thundra_apiKey: <your_api_key>
  • Add the Thundra layer to Layers in globals section. ThundraAWSAccountNo and ThundraPythonLayerVersion parameters are defined under the Parameters section in the following configuration:

Latest version of the Thundra's Node.js layer:

Parameters:
ThundraAWSAccountNo:
Type: Number
Default: 269863060030
ThundraNodeLayerVersion:
Type: Number
Default: 24 # Or use any other version
Globals:
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::Function
Properties:
Runtime: provided
Handler: handler.hello

An example configuration:

Parameters:
ThundraAWSAccountNo:
Type: Number
Default: 269863060030
ThundraNodeLayerVersion:
Type: Number
Default: 24 # Or use any other version
Globals:
Function:
Runtime: provided
Timeout: 5
Environment:
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::Function
Properties:
CodeUri: ./
Handler: handler.hello

Step 2: Test / Deploy

To build & run your functions locally:

sam build && sam local invoke

Then, package and deploy your function using sam.

Step 2: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!