AWS Lambda Native Tracing for Python
You can setup Instana AWS Lambda tracing for AWS Lambda functions written in Python.
For more information, see AWS Lambda tracing.
Supported Runtimes
-
Python 3.13 -
Python 3.12 -
Python 3.11 -
Python 3.10 -
Python 3.9
Prerequisites
Set up the AWS agent for Lambda monitoring to collect versions and runtime metrics that Instana cannot collect from inside the AWS Lambda runtime.
Configuring AWS Lambda functions
You can enable tracing of Lambda functions by using one of the following setup options:
- Using the Instana Lambda layer: Zero-code instrumentation of the Lambda function done purely through configuration. This method is the preferred for enabling tracing.
- Installing the
instanapackage manually: For restricted environments, such as FedRAMP-compliant environments, you can to install the Instana Python Tracer package manually.
Using the Instana Lambda layer
To enable tracing of Python Lambda functions through the AWS web console, perform the following steps:
Step 1. Add the Instana Lambda layer to your function
- On the configuration page for your Lambda function, click the Layers box.
Figure 1. Lambda Layers
- Click Add a layer in the Layers box.
Figure 2. Add a layer
- On the new page that opens, select the Specify an ARN option as the layer source. Copy and paste the ARN for the Instana Lambda Layer that matches your region in the Specify an ARN field, and then click Add. You can find the right ARN for the Instana Lambda Layer in the Instana Lambda Layers section.
Step 2. Configure the Lambda handler
Set the Lambda handler to instana.lambda_handler. On the function configuration page, go to the Runtime settings section, and click Edit.
In the Handler field, insert instana.lambda_handler, and then click Save.
If you are using a custom handler value (instead of the default handler for your runtime, see preceding details), specify your handler in the environment variable LAMBDA_HANDLER to notify the Instana Lambda Layer. For example, if your handler is myModule.myHandler, set the environment variable LAMBDA_HANDLER to myModule.myHandler. For other environment variables that need to be set, see the next section.
Lambda can't find the file instana.lambda_handler.. This message can also be displayed later when you return to the configuration page. You can ignore this warning because the handler is included in the Instana Lambda layer, but the AWS Lambda configuration page does not take that into account.Step 3. Configure environment variables
Add the following environment variables:
-
INSTANA_ENDPOINT_URL: Your serverless monitoring endpoint. Make sure to use the correct value for your region that starts withhttps://serverless-. -
INSTANA_AGENT_KEY: Your agent key. -
LAMBDA_HANDLER: Your custom handler, if you are not using the default handlerlambda_function.lambda_handler.
You can also find the correct values for these environment variables in your Instana installation. Go to Data sources > Install agents > AWS Lambda.
Step 4. Using the AWS Command Line Interface (CLI)
You can also enable tracing of Lambda functions by using any of the following AWS management tools:
The following example shows an aws CLI command that might serve as a starting point if you want to automate the Instana integration of your AWS Lambda functions:
# Do not copy and paste this verbatim!
# It will overwrite any previously defined collection of layers and environment variables.
aws --region $YOUR_REGION lambda update-function-configuration \
--function-name $YOUR_LAMBDA_FUNCTION_NAME \
--layers $INSTANA_LAYER_ARN \
--handler instana.lambda_handler \
--environment ""Variables={INSTANA_ENDPOINT_URL=... , INSTANA_AGENT_KEY=... , ...}""
Installing the instana package manually
Instead of using the Instana Lambda layer, you can also choose to install the Instana Python Tracer package manually. This option is preferable for restricted environments, such as FedRAMP-compliant environments.
To enable tracing of Python Lambda functions, complete the following steps:
- Add the Instana Python Tracer package as dependency to your function project. [1]
- Set the Lambda handler to
instana.lambda_handleras described in the Configuring Lambda handler section. - Configure the following environment variables for the Lambda function:
-
INSTANA_ENDPOINT_URL: Your serverless monitoring endpoint. Make sure to use the correct value for your region that starts withhttps://serverless-. -
INSTANA_AGENT_KEY: Your agent key. -
LAMBDA_HANDLER: Your custom handler, if you are not using the default handlerlambda_function.lambda_handler.
-
Instana Lambda layers
The ARNs of the latest version of the AWS Lambda layers for Python are the following, per region:
| Region | ARN |
|---|---|
af-south-1 |
arn:aws:lambda:af-south-1:410797082306:layer:instana-python:89 |
ap-east-1 |
arn:aws:lambda:ap-east-1:410797082306:layer:instana-python:89 |
ap-northeast-1 |
arn:aws:lambda:ap-northeast-1:410797082306:layer:instana-python:89 |
ap-northeast-2 |
arn:aws:lambda:ap-northeast-2:410797082306:layer:instana-python:89 |
ap-northeast-3 |
arn:aws:lambda:ap-northeast-3:410797082306:layer:instana-python:89 |
ap-south-1 |
arn:aws:lambda:ap-south-1:410797082306:layer:instana-python:89 |
ap-south-2 |
arn:aws:lambda:ap-south-2:410797082306:layer:instana-python:89 |
ap-southeast-1 |
arn:aws:lambda:ap-southeast-1:410797082306:layer:instana-python:89 |
ap-southeast-2 |
arn:aws:lambda:ap-southeast-2:410797082306:layer:instana-python:89 |
ap-southeast-3 |
arn:aws:lambda:ap-southeast-3:410797082306:layer:instana-python:89 |
ap-southeast-4 |
arn:aws:lambda:ap-southeast-4:410797082306:layer:instana-python:89 |
ap-southeast-5 |
arn:aws:lambda:ap-southeast-5:410797082306:layer:instana-python:89 |
ap-southeast-7 |
arn:aws:lambda:ap-southeast-7:410797082306:layer:instana-python:89 |
ca-central-1 |
arn:aws:lambda:ca-central-1:410797082306:layer:instana-python:89 |
ca-west-1 |
arn:aws:lambda:ca-west-1:410797082306:layer:instana-python:89 |
cn-north-1 |
arn:aws-cn:lambda:cn-north-1:107998019096:layer:instana-python:89 |
cn-northwest-1 |
arn:aws-cn:lambda:cn-northwest-1:107998019096:layer:instana-python:89 |
eu-central-1 |
arn:aws:lambda:eu-central-1:410797082306:layer:instana-python:89 |
eu-central-2 |
arn:aws:lambda:eu-central-2:410797082306:layer:instana-python:89 |
eu-north-1 |
arn:aws:lambda:eu-north-1:410797082306:layer:instana-python:89 |
eu-south-1 |
arn:aws:lambda:eu-south-1:410797082306:layer:instana-python:89 |
eu-south-2 |
arn:aws:lambda:eu-south-2:410797082306:layer:instana-python:89 |
eu-west-1 |
arn:aws:lambda:eu-west-1:410797082306:layer:instana-python:89 |
eu-west-2 |
arn:aws:lambda:eu-west-2:410797082306:layer:instana-python:89 |
eu-west-3 |
arn:aws:lambda:eu-west-3:410797082306:layer:instana-python:89 |
il-central-1 |
arn:aws:lambda:il-central-1:410797082306:layer:instana-python:89 |
me-central-1 |
arn:aws:lambda:me-central-1:410797082306:layer:instana-python:89 |
me-south-1 |
arn:aws:lambda:me-south-1:410797082306:layer:instana-python:89 |
sa-east-1 |
arn:aws:lambda:sa-east-1:410797082306:layer:instana-python:89 |
us-east-1 |
arn:aws:lambda:us-east-1:410797082306:layer:instana-python:89 |
us-east-2 |
arn:aws:lambda:us-east-2:410797082306:layer:instana-python:89 |
us-west-1 |
arn:aws:lambda:us-west-1:410797082306:layer:instana-python:89 |
us-west-2 |
arn:aws:lambda:us-west-2:410797082306:layer:instana-python:89 |
The pattern for Chinese regions is arn:aws-cn:lambda:${region}:107998019096:layer:instana-python:${layer-version} and for the rest of the regions is arn:aws:lambda:${region}:410797082306:layer:instana-python:${layer-version}.
Make sure to always use the latest versions and update the layer version you are using in regular intervals to benefit from new features and fixes that we provide when publishing a new version of the layer.
Troubleshooting
Order of layers may impact Instana layer performance
When you add multiple layers to a Python Lambda function, the order of addition impacts the performance of the Instana layer. To make sure that the Instana layer traces correctly, place it in the last position (the highest number) of the layers merge order.
-
Follow the official AWS Lambda documentation to create a .zip deployment package with dependencies. ↩︎