Thundra APM
Search…
Deployment Integrations
Powered By GitBook
Integration Options for Python SDK
Using Layers
Without Layers
Serverless Framework
AWS SAM
AWS CDK

Using Layers

Step 1: Deploy Your Function to AWS Lambda

Bundle all your Python module files and any additional required Python libraries, 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

Step 2: Configure Your Function

Add the API key to the environment variables on the Amazon Lambda console.
Add Thundra layer
Next, add the Thundra layer by clicking on the Layers option in the Designer tab on your Lambda function console. Then select the “Add Layer” button and add the Thundra layer's ARN.
1
arn:aws:lambda:${region}:269863060030:layer:thundra-lambda-python-layer:${latest-version}
Copied!
Latest layer version of thundra python layer
Note that the region of the ARN is dynamic, so you need to change it accordingly to the region where you deploy your function. So let’s say that you deploy your Lambda function to the Oregon (us-west-2) region. The layer ARN will be:arn:aws:lambda:us-west-2:269863060030:layer:thundra-lambda-python-layer:${layer-version}
Configure handler
Set the handler to thundra.handler.wrapper. Set the thundra_agent_lambda_handler environment variable value to your original handler (e.g., handler.handle).
Step 3: Invoke your deployed function by clicking on the Test button on the top right
Clicking on the “Test” button, which is located on the top right side of the AWS console, will result in an invocation of your function (after you have configured test data per the specifications of your function).
Step 4: Monitor your function with Thundra After generating your first invocation, the “Next” button will appear in the Invocation Monitor bar. Simply click the button to see monitoring data from your invocation.

Without Layers

Step 1: Install Thundra’s python package

In the project directory, run the following command:
1
pip3 install thundra -t .
Copied!

Step 2: Deploy Your Function to AWS Lambda.

Bundle all your Python module files and any additional required Python libraries, and then upload it to the AWS Lambda console using the “Upload a.zip file” option for the code entry type.

Step 3: Configure Your Function

Add the API key to the environment variables on the Amazon Lambda console.
Configure Handler
Set the handler to thundra.handler.wrapper. Set the thundra_agent_lambda_handler environment variable value to your handler.

Step 4: Invoke Your Deployed Function

Clicking on the “Test” button, which is located on the top right side of the AWS console, will result in an invocation of your function (after you have configured test data per the specifications of your function).

Step 5: Monitor Your Function with Thundra

After generating your first invocation, the “Next” button will appear in the Invocation Monitor bar. Simply click the button to see monitoring data from your invocation.

Serverless Framework

Step 1: Install Thundra’s Serverless Plugin to Automatically Wrap Your Functions

1
npm install serverless-plugin-thundra
Copied!

Step 2: Add Thundra's Serverless Plugin in serverless.yml File

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.yml
1
plugins:
2
- serverless-plugin-thundra
Copied!

Step 3: Add thundra component to custom

Add the thundra component under custom with apiKey under that, as seen below:
serverless.yml
1
custom:
2
thundra:
3
apiKey: <YOUR THUNDRA API KEY>
Copied!
Step 4: Add the thundra_apiKey to Environment Variables under the Provider Section in serverless.yml
serverless.yml
1
provider:
2
environment:
3
thundra_apiKey: <YOUR THUNDRA API KEY>
Copied!

Step 5: Deploy and Test app

1
serverless deploy
2
serverless invoke --function functionName
Copied!

Step 6: Monitor Your Function with Thundra

After generating your first invocation, the “Next” button will appear in the Invocation Monitor bar. Simply click the button to see monitoring data from your invocation.

AWS SAM

Step 1: Add Configuration Changes on the SAM template.yml

    Add the thundra_apiKey environment variable along with your Thundra API key.
1
Globals:
2
Function:
3
...
4
Environment:
5
Variables:
6
thundra_apiKey: <your_api_key>
Copied!
    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 layer version of thundra python layer:
1
ThundraAWSAccountNo:
2
Type: Number
3
Default: 269863060030
4
5
ThundraPythonLayerVersion:
6
Type: Number
7
Default: 12 # Or use any other version
8
9
Globals:
10
...
11
Function:
12
...
13
Layers:
14
- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-python-layer:${ThundraPythonLayerVersion}
15
16
17
Copied!
    Change the handler of functions to be wrapped to thundra.handler.wrapper. Alternatively, if you want to wrap all the functions in your SAM configuration file, you can set the handler in the Globals section.
1
Globals:
2
Function:
3
...
4
5
Handler: thundra.handler.wrapper
6
Copied!
    For each wrapped function, add the thundra_agent_lambda_handler environment variable with the value set to the handler path of your function.
1
Resources:
2
HelloWorldFunction1:
3
Type: AWS::Serverless::Function
4
Properties:
5
Environment:
6
Variables:
7
thundra_agent_lambda_handler: hello_world_1.app.lambda_handler
8
Copied!
An example configuration:
1
Parameters:
2
ThundraAWSAccountNo:
3
Type: Number
4
Default: 269863060030
5
6
ThundraPythonLayerVersion:
7
Type: Number
8
Default: 11 # Or use any other version
9
10
Globals:
11
Function:
12
Runtime: python3.7
13
Timeout: 5
14
15
Handler: thundra.handler.wrapper
16
Layers:
17
- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-python-layer:${ThundraPythonLayerVersion}
18
19
Environment:
20
Variables:
21
thundra_apiKey: <your_api_key>
22
23
Resources:
24
HelloWorldFunction1:
25
Type: AWS::Serverless::Function
26
Properties:
27
Environment:
28
Variables:
29
thundra_agent_lambda_handler: hello_world_1.app.lambda_handler
30
Copied!

Step 2: Test the Application

To build and run your functions locally:
1
sam build && sam local invoke
Copied!

Step 3: Monitor Your Function with Thundra

After generating your first invocation, the “Next” button will appear in the Invocation Monitor bar. Simply click the button to see monitoring data from your invocation.

AWS CDK

Step 1: Apply Configuration Changes to Your Function Properties

    Add the thundra_apiKey environment variable with your Thundra API key.
1
from aws_cdk import (core,
2
aws_lambda as lambda_)
3
4
class YourConstructClass(core.Construct):
5
6
def __init__(self, scope: core.Construct, id: str):
7
super().__init__(scope, id)
8
9
thundraApiKey = <your_api_key>
10
11
handler = lambda_.Function(self, "YourHandler",
12
..., # other function properties
13
environment=dict(
14
..., # other environment variables
15
thundra_apiKey=thundraApiKey)
Copied!
    Define the Thundra layer and add it to your function properties.
Latest layer version of thundra python layer:
1
from aws_cdk import (core,
2
aws_lambda as lambda_)
3
4
5
class YourConstructClass(core.Construct):
6
7
def __init__(self, scope: core.Construct, id: str):
8
super().__init__(scope, id)
9
10
thundraApiKey = <your_api_key>
11
thundraAWSAccountNo = 269863060030
12
thundraPythonLayerVersion = 31 # or any other version
13
thundraPythonLayer = lambda_.LayerVersion.from_layer_version_arn(self, "ThundraLayer",
14
"arn:aws:lambda:{}:{}:layer:thundra-lambda-python-layer:{}".format(
15
core.Aws.REGION, thundraAWSAccountNo, thundraPythonLayerVersion)),
16
17
handler = lambda_.Function(self, "YourHandler",
18
..., # other function properties
19
environment=dict(
20
..., # other environment variables
21
thundra_apiKey=thundraApiKey),
22
layers=[
23
thundraPythonLayer,
24
... # other layers
25
]
26
)
Copied!
Aws.REGION is a pseudo parameter which is bootstrapped from your stack's environment configuration.
    Change the handler of your function to thundra.handler.wrapper, and add the environment variable thundra_agent_lambda_handler with your handler.
1
from aws_cdk import (core,
2
aws_lambda as lambda_)
3
4
class YourConstructClass(core.Construct):
5
6
def __init__(self, scope: core.Construct, id: str):
7
super().__init__(scope, id)
8
9
thundraApiKey = <your_api_key>
10
thundraAWSAccountNo = 269863060030
11
thundraPythonLayerVersion = 31 # or any other version
12
thundraPythonLayer = lambda_.LayerVersion.from_layer_version_arn(self, "ThundraLayer",
13
"arn:aws:lambda:{}:{}:layer:thundra-lambda-python-layer:{}".format(
14
core.Aws.REGION, thundraAWSAccountNo, thundraPythonLayerVersion)),
15
16
handler = lambda_.Function(self, "YourHandler",
17
..., # other function properties
18
handler=thundra.handler.wrapper
19
environment=dict(
20
..., # other environment variables
21
thundra_apiKey=thundraApiKey,
22
thundra_agent_lambda_handler=<your_handler>),
23
layers=[
24
thundraPythonLayer,
25
... # other layers
26
]
27
)
Copied!
An example configuration:
1
from aws_cdk import (core,
2
aws_lambda as lambda_)
3
4
class YourConstructClass(core.Construct):
5
6
def __init__(self, scope: core.Construct, id: str):
7
super().__init__(scope, id)
8
9
thundraApiKey = <your_api_key>
10
thundraAWSAccountNo = 269863060030
11
thundraPythonLayerVersion = 31
12
thundraPythonLayer = lambda_.LayerVersion.from_layer_version_arn(self, "ThundraLayer",
13
"arn:aws:lambda:{}:{}:layer:thundra-lambda-python-layer:{}".format(
14
core.Aws.REGION, thundraAWSAccountNo,
15
thundraPythonLayerVersion))
16
17
with open("your-lambda-handler.py", encoding="utf8") as fp:
18
handler_code = fp.read()
19
20
handler = lambda_.Function(self, "YourHandler",
21
runtime=lambda_.Runtime.PYTHON_3_8,
22
code=lambda_.InlineCode(handler_code),
23
handler="thundra.handler.wrapper",
24
environment=dict(
25
thundra_apiKey2=thundraApiKey,
26
thundra_agent_lambda_handler="your.handler"),
27
layers=[
28
thundraPythonLayer]
29
)
Copied!

Step 2: Build and Deploy

1
cdk deploy
Copied!

Step 3: Invoke Your Function!

Now you can invoke your Lambda function and see the details of your invocation in the Thundra console!
Last modified 10mo ago
Copy link