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}
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_apiKey
environment variable to your api key you get from the Thundra console.
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.
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.jsconst 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.
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 functions. All you have to do is installing @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 functions 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 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.
In the AWS Lambda console, set the thundra_apiKey the 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!
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.ymlplugins:- serverless-plugin-thundra
Step 3: Add thundra
component to custom
Add the thundra
component under custom
with apiKey
under that, as seen below:
serverless.ymlcustom:thundra:apiKey: <YOUR THUNDRA API KEY>
Step 4: Add thundra_apiKey
to environment variables under provider section in serverless.yml
serverless.ymlprovider:environment:thundra_apiKey: <YOUR THUNDRA API KEY>
Step 5: Deploy
serverless deploy
Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!
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: 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 & run your functions locally:
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!