Integration Options

Using Layers
Without Layers
Serverless Framework
AWS SAM

Using Layers

Step 1: Deploy your function to AWS Lambda Bundle all your Java class files, along with any additional required Java libraries 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 api key to the environment variables on Amazon Lambda Console

  • Add Thundra layer

    Click on the Layers option on your Lambda function console in the Designer tab. Then select Add Layer button and add Thundra Layer's ARN.

arn:aws:lambda:${region}:269863060030:layer:thundra-lambda-java-layer:${latest-version}

You can use the following latest layer version instead of ${latest-version} above.

Note that the region part of the ARN is dynamic, so you need to change it according to the region where you deploy your function. So let say that you deploy your Lambda function to Oregon (us-west-2) region, and the layer version is 29. The layer ARN will be:arn:aws:lambda:us-west-2:269863060030:layer:thundra-lambda-java-layer:29

  • Configure handler

    Set handler to io.thundra.agent.lambda.core.handler.ThundraLambdaHandler. Set thundra_agent_lambda_handler environment variable value to to your handler.

Step 3: Invoke your deployed function by clicking on the Test button on the top right

Clicking on the 'Test' button on the top right of the AWS console will result in an invocation of your function after you have configured test data as per the specifications of your function.

Step 4: Monitor your function with Thundra Upon your first invocation ever, the Next button shall appear in the Invocation Monitor bar below and clicking it shall allow you to see monitoring data from your invocation.

Custom Runtime

Using the Thundra's Java custom runtime, you can integrate Thundra to your Java Lambda functions with zero code and configuration 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 and NO Handler configuration change is needed.

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

Good bye to cold starts with fast startup mode

Additionally, with Thundra Java Custom Runtime, it is now possible tuning Java-based Lambda applications to start faster for reducing cold start overhead. Java is one of the languages that suffers from cold start overhead most on AWS Lambda. Until now, with managed Java runtime, it was not feasible to optimize a Java process to start faster. Even though, AWS Lambda already makes some optimizations to start process faster for Java runtime by enabling class data sharing with -Xshare:on so classes are loaded from a shared memory mapped file in some pre-parsed format, there are still some other options to tune Java application startup time. With Thundra Java Custom Runtime support, you already get these optimizations out of the box, by setting thundra_agent_lambda_jvm_optimizeForFastStartup environment variable to true, as we use AWS Lambda’s JVM which is pre-installed on the custom runtime environment already and you will get have lover cold start overhead. If you are in trouble with the cold start overhead for your Java-based Lambda function, give it a try and see the effect.

Without Layers

Step 1: Install Thundra’s Java library On the project directory run following command:

<dependency>
<groupId>io.thundra.agent</groupId>
<artifactId>thundra-agent-lambda-all</artifactId>
<type>pom</type>
<version>${thundra.version}</version>
</dependency>

You can use the following version instead of ${thundra.version}

Step 2: Deploy your function to AWS Lambda Bundle all your Java module files, along with any additional required Java libraries/dependencies and upload it to the AWS Lambda console using the 'Upload a.zip file' option for the code entry type option.

Step 3: Configure your function

  • Add api key to the environment variables on Amazon Lambda Console

  • Configure handler

    Set handler to io.thundra.agent.lambda.core.handler.ThundraLambdaHandler. Set thundra_agent_lambda_handler environment variable value to to your handler.

Step 4: Invoke your deployed function by clicking on the Test button on the top right

Clicking on the 'Test' button on the top right of the AWS console will result in an invocation of your function after you have configured test data as per the specifications of your function.

Step 5: Monitor your function with Thundra Upon your first invocation ever, the Next button shall appear in the Invocation Monitor bar below and clicking it shall allow you to see monitoring data from your invocation.

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 & Test app

serverless deploy
serverless invoke --function functionName

Step 6: Monitor your function with Thundra

Upon your first invocation ever, the Next button shall appear in the Invocation Monitor bar below and clicking it shall allow you to see monitoring data from your invocation.

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 ThundraJavaLayerVersion parameters are defined under the Parameters section in the following configuration:

Latest layer version of Thundra Java layer:

Parameters:
ThundraAWSAccountNo:
Type: Number
Default: 269863060030
ThundraJavaLayerVersion:
Type: Number
Default: 29 # Or use any other version
Globals:
...
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-java-layer:${ThundraJavaLayerVersion}
  • Change Handler of functions to be wrapped to

    io.thundra.agent.lambda.core.handler.ThundraLambdaHandler

    or set Handler in the Globals section if you want to wrap all of the functions in your SAM configuration file.

Globals:
Function:
...
Handler: io.thundra.agent.lambda.core.handler.ThundraLambdaHandler
  • For each function that is wrapped, add thundra_agent_lambda_handler environment variable with handler full classname (package and class name) of your function.

Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
thundra_agent_lambda_handler: com.mycompany.MyHandler

An example configuration:

Parameters:
ThundraAWSAccountNo:
Type: Number
Default: 269863060030
ThundraJavaLayerVersion:
Type: Number
Default: 29 # Or use any other version
Globals:
Function:
Runtime:
Timeout: 5
Handler: io.thundra.agent.lambda.core.handler.ThundraLambdaHandler
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-java-layer:${ThundraJavaLayerVersion}
Environment:
Variables:
thundra_apiKey: <your_api_key>
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
thundra_agent_lambda_handler: com.mycompany.MyHandler

Step 2: Test application

To build & run your functions locally:

sam build && sam local invoke

Step 3: Monitor your function with Thundra

Upon your first invocation ever, the Next button shall appear in the Invocation Monitor bar below and clicking it shall allow you to see monitoring data from your invocation.