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
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.
arn:aws:lambda:${region}:269863060030:layer:thundra-lambda-python-layer:${latest-version}
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.
In the project directory, run the following command:
pip3 install thundra -t .
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.
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.
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).
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.
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
Add the thundra
component under custom with apiKey under that, as seen below:
serverless.ymlcustom:thundra:apiKey: <YOUR THUNDRA API KEY>
Step 4: Add the thundra_apiKey
to Environment Variables under the Provider Section in serverless.yml
serverless.ymlprovider:environment:thundra_apiKey: <YOUR THUNDRA API KEY>
serverless deployserverless invoke --function functionName
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.
Add the thundra_apiKey
environment variable along with 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 layer version of thundra python layer:
ThundraAWSAccountNo:Type: NumberDefault: 269863060030ThundraPythonLayerVersion:Type: NumberDefault: 12 # Or use any other versionGlobals:...Function:...Layers:- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-python-layer:${ThundraPythonLayerVersion}…
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.
Globals:Function:...Handler: thundra.handler.wrapper
For each wrapped function, add the thundra_agent_lambda_handler
environment variable with the value set to the handler path of your function.
Resources:HelloWorldFunction1:Type: AWS::Serverless::FunctionProperties:Environment:Variables:thundra_agent_lambda_handler: hello_world_1.app.lambda_handler
An example configuration:
Parameters:ThundraAWSAccountNo:Type: NumberDefault: 269863060030ThundraPythonLayerVersion:Type: NumberDefault: 11 # Or use any other versionGlobals:Function:Runtime: python3.7Timeout: 5Handler: thundra.handler.wrapperLayers:- !Sub arn:aws:lambda:${AWS::Region}:${ThundraAWSAccountNo}:layer:thundra-lambda-python-layer:${ThundraPythonLayerVersion}Environment:Variables:thundra_apiKey: <your_api_key>Resources:HelloWorldFunction1:Type: AWS::Serverless::FunctionProperties:Environment:Variables:thundra_agent_lambda_handler: hello_world_1.app.lambda_handler
To build and run your functions locally:
sam build && sam local invoke
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.
Add the thundra_apiKey
environment variable with your Thundra API key.
from aws_cdk import (core,aws_lambda as lambda_)class YourConstructClass(core.Construct):def __init__(self, scope: core.Construct, id: str):super().__init__(scope, id)thundraApiKey = <your_api_key>handler = lambda_.Function(self, "YourHandler",..., # other function propertiesenvironment=dict(..., # other environment variablesthundra_apiKey=thundraApiKey)
Define the Thundra layer and add it to your function properties.
Latest layer version of thundra python layer:
from aws_cdk import (core,aws_lambda as lambda_)class YourConstructClass(core.Construct):def __init__(self, scope: core.Construct, id: str):super().__init__(scope, id)thundraApiKey = <your_api_key>thundraAWSAccountNo = 269863060030thundraPythonLayerVersion = 31 # or any other versionthundraPythonLayer = lambda_.LayerVersion.from_layer_version_arn(self, "ThundraLayer","arn:aws:lambda:{}:{}:layer:thundra-lambda-python-layer:{}".format(core.Aws.REGION, thundraAWSAccountNo, thundraPythonLayerVersion)),handler = lambda_.Function(self, "YourHandler",..., # other function propertiesenvironment=dict(..., # other environment variablesthundra_apiKey=thundraApiKey),layers=[thundraPythonLayer,... # other layers])
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.
from aws_cdk import (core,aws_lambda as lambda_)class YourConstructClass(core.Construct):def __init__(self, scope: core.Construct, id: str):super().__init__(scope, id)thundraApiKey = <your_api_key>thundraAWSAccountNo = 269863060030thundraPythonLayerVersion = 31 # or any other versionthundraPythonLayer = lambda_.LayerVersion.from_layer_version_arn(self, "ThundraLayer","arn:aws:lambda:{}:{}:layer:thundra-lambda-python-layer:{}".format(core.Aws.REGION, thundraAWSAccountNo, thundraPythonLayerVersion)),handler = lambda_.Function(self, "YourHandler",..., # other function propertieshandler=thundra.handler.wrapperenvironment=dict(..., # other environment variablesthundra_apiKey=thundraApiKey,thundra_agent_lambda_handler=<your_handler>),layers=[thundraPythonLayer,... # other layers])
An example configuration:
from aws_cdk import (core,aws_lambda as lambda_)class YourConstructClass(core.Construct):def __init__(self, scope: core.Construct, id: str):super().__init__(scope, id)thundraApiKey = <your_api_key>thundraAWSAccountNo = 269863060030thundraPythonLayerVersion = 31thundraPythonLayer = lambda_.LayerVersion.from_layer_version_arn(self, "ThundraLayer","arn:aws:lambda:{}:{}:layer:thundra-lambda-python-layer:{}".format(core.Aws.REGION, thundraAWSAccountNo,thundraPythonLayerVersion))with open("your-lambda-handler.py", encoding="utf8") as fp:handler_code = fp.read()handler = lambda_.Function(self, "YourHandler",runtime=lambda_.Runtime.PYTHON_3_8,code=lambda_.InlineCode(handler_code),handler="thundra.handler.wrapper",environment=dict(thundra_apiKey2=thundraApiKey,thundra_agent_lambda_handler="your.handler"),layers=[thundraPythonLayer])
cdk deploy
Now you can invoke your Lambda function and see the details of your invocation in the Thundra console!