AWS Lambda Native Tracing for Python
This page covers the setup for Instana AWS Lambda tracing for AWS Lambda functions written in Python.
For more information, see AWS Lambda tracing.
Supported Runtimes
Python 3.13Python 3.12Python 3.11Python 3.10Python 3.9
Starting from 14 October 2024, AWS Lambda no longer applies security patches and other updates to the Python 3.8 runtime that is used by Lambda functions. The functions that use Python 3.8 are no longer eligible for technical support, and you can no longer create new Lambda functions that use the Python 3.8 runtime.
Installation
This documentation explains how to set up the tracing of Python Lambda functions. Ensure that you also have performed the setup of the AWS agent for Lambda monitoring to ensure the collection of necessary information about versions and some runtime metrics that Instana cannot collect from inside the AWS Lambda runtime.
To enable tracing of Python Lambda functions, perform the following steps:
1. Add the Instana Lambda layer to your function
- On the configuration page for your Lambda function, click the Layers box.
- Click Add a layer in the Layers box.
- 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.
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.
The Lambda configuration page might display a warning like 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.
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.
4. Using the AWS Command Line Interface (CLI)
All the steps outlined earlier can be done either by using the AWS web console or any of the usual AWS management tools, such as:
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=... , ...}""
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:81 |
ap-east-1 |
arn:aws:lambda:ap-east-1:410797082306:layer:instana-python:81 |
ap-northeast-1 |
arn:aws:lambda:ap-northeast-1:410797082306:layer:instana-python:81 |
ap-northeast-2 |
arn:aws:lambda:ap-northeast-2:410797082306:layer:instana-python:81 |
ap-northeast-3 |
arn:aws:lambda:ap-northeast-3:410797082306:layer:instana-python:81 |
ap-south-1 |
arn:aws:lambda:ap-south-1:410797082306:layer:instana-python:81 |
ap-south-2 |
arn:aws:lambda:ap-south-2:410797082306:layer:instana-python:81 |
ap-southeast-1 |
arn:aws:lambda:ap-southeast-1:410797082306:layer:instana-python:81 |
ap-southeast-2 |
arn:aws:lambda:ap-southeast-2:410797082306:layer:instana-python:81 |
ap-southeast-3 |
arn:aws:lambda:ap-southeast-3:410797082306:layer:instana-python:81 |
ap-southeast-4 |
arn:aws:lambda:ap-southeast-4:410797082306:layer:instana-python:81 |
ap-southeast-5 |
arn:aws:lambda:ap-southeast-5:410797082306:layer:instana-python:81 |
ap-southeast-7 |
arn:aws:lambda:ap-southeast-7:410797082306:layer:instana-python:81 |
ca-central-1 |
arn:aws:lambda:ca-central-1:410797082306:layer:instana-python:81 |
ca-west-1 |
arn:aws:lambda:ca-west-1:410797082306:layer:instana-python:81 |
cn-north-1 |
arn:aws-cn:lambda:cn-north-1:107998019096:layer:instana-python:81 |
cn-northwest-1 |
arn:aws-cn:lambda:cn-northwest-1:107998019096:layer:instana-python:81 |
eu-central-1 |
arn:aws:lambda:eu-central-1:410797082306:layer:instana-python:81 |
eu-central-2 |
arn:aws:lambda:eu-central-2:410797082306:layer:instana-python:81 |
eu-north-1 |
arn:aws:lambda:eu-north-1:410797082306:layer:instana-python:81 |
eu-south-1 |
arn:aws:lambda:eu-south-1:410797082306:layer:instana-python:81 |
eu-south-2 |
arn:aws:lambda:eu-south-2:410797082306:layer:instana-python:81 |
eu-west-1 |
arn:aws:lambda:eu-west-1:410797082306:layer:instana-python:81 |
eu-west-2 |
arn:aws:lambda:eu-west-2:410797082306:layer:instana-python:81 |
eu-west-3 |
arn:aws:lambda:eu-west-3:410797082306:layer:instana-python:81 |
il-central-1 |
arn:aws:lambda:il-central-1:410797082306:layer:instana-python:81 |
me-central-1 |
arn:aws:lambda:me-central-1:410797082306:layer:instana-python:81 |
me-south-1 |
arn:aws:lambda:me-south-1:410797082306:layer:instana-python:81 |
sa-east-1 |
arn:aws:lambda:sa-east-1:410797082306:layer:instana-python:81 |
us-east-1 |
arn:aws:lambda:us-east-1:410797082306:layer:instana-python:81 |
us-east-2 |
arn:aws:lambda:us-east-2:410797082306:layer:instana-python:81 |
us-west-1 |
arn:aws:lambda:us-west-1:410797082306:layer:instana-python:81 |
us-west-2 |
arn:aws:lambda:us-west-2:410797082306:layer:instana-python:81 |
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.