AWS Lambda Native Tracing for Python

This page covers the setup for Instana AWS Lambda tracing for AWS Lambda functions written in Python.

Supported Runtimes

  • Python 3.12
  • Python 3.11
  • Python 3.10
  • Python 3.9
  • Python 3.8

Tracing support for Tornado, asyncio, and aiohttp is limited to the runtimes of Python up to 3.10.

Starting from November 27 2023, AWS Lambda no longer applies security patches and other updates to the Python 3.7 runtime that is used by Lambda functions. The functions that use Python 3.7 are no longer eligible for technical support, and the customers are no longer able to create Lambda functions that use the Python 3.7 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.

    1. In the configuration page for your Lambda function, click on the Layers box and then on Add a layer. layer
    2. In the popup that opens, select "Provide a layer version ARN" and copy and paste the ARN for the Instana Lambda Layer that matches your region; you can find the right ARN for the Instana Lambda Layer in the Instana Lambda Layers section. layer selection
  2. Configure the Lambda Handler. Set the handler to instana.lambda_handler. The Instana Lambda layer will automatically trigger the default Python runtime handler: lambda_function.lambda_handler.

    To change the setting for the Lambda handler, find the "Basic Settings" section on the configuration page. basic settings section edit button

    Click on edit and insert instana.lambda_handler into the field labeled "Handler". edit basic settings to set Instana's handler

    If you are using a custom handler value (as opposed to the default handler for your runtime, see above), specify your handler in the environment variable LAMBDA_HANDLER to notify the Instana Lambda Layer. That is, if your handler is myModule.myHandler, set the environment variable LAMBDA_HANDLER to myModule.myHandler. See the next section for other environment variables that need to be set.

    Note: The Lambda configuration page might display a warning like Lambda can't find the file instana.lambda_handler.. This might also be displayed later when returning to the configuration page. Do not let this warning distract you. The handler is contained 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:

    You can also obtain the correct values for these environment variables by going to your Instana installation, click on "... More" -> "Agents" -> "Installing Instana Agents" -> Platform: "AWS" -> Technology: "AWS Lambda".

  4. Save the Lambda function definition. save

All the steps outlined above can be done either via the AWS web console or any of the usual AWS management tools, such as:

Here is an example aws CLI command that might serve as a starting point if you want to automate the Instana integration of your AWS Lambdas:

# 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:61
ap-east-1 arn:aws:lambda:ap-east-1:410797082306:layer:instana-python:61
ap-northeast-1 arn:aws:lambda:ap-northeast-1:410797082306:layer:instana-python:61
ap-northeast-2 arn:aws:lambda:ap-northeast-2:410797082306:layer:instana-python:61
ap-northeast-3 arn:aws:lambda:ap-northeast-3:410797082306:layer:instana-python:61
ap-south-1 arn:aws:lambda:ap-south-1:410797082306:layer:instana-python:61
ap-south-2 arn:aws:lambda:ap-south-2:410797082306:layer:instana-python:61
ap-southeast-1 arn:aws:lambda:ap-southeast-1:410797082306:layer:instana-python:61
ap-southeast-2 arn:aws:lambda:ap-southeast-2:410797082306:layer:instana-python:61
ap-southeast-3 arn:aws:lambda:ap-southeast-3:410797082306:layer:instana-python:61
ap-southeast-4 arn:aws:lambda:ap-southeast-4:410797082306:layer:instana-python:61
ca-central-1 arn:aws:lambda:ca-central-1:410797082306:layer:instana-python:61
ca-west-1 arn:aws:lambda:ca-west-1:410797082306:layer:instana-python:61
cn-north-1 arn:aws-cn:lambda:cn-north-1:107998019096:layer:instana-python:60
cn-northwest-1 arn:aws-cn:lambda:cn-northwest-1:107998019096:layer:instana-python:60
eu-central-1 arn:aws:lambda:eu-central-1:410797082306:layer:instana-python:61
eu-central-2 arn:aws:lambda:eu-central-2:410797082306:layer:instana-python:61
eu-north-1 arn:aws:lambda:eu-north-1:410797082306:layer:instana-python:61
eu-south-1 arn:aws:lambda:eu-south-1:410797082306:layer:instana-python:61
eu-south-2 arn:aws:lambda:eu-south-2:410797082306:layer:instana-python:61
eu-west-1 arn:aws:lambda:eu-west-1:410797082306:layer:instana-python:61
eu-west-2 arn:aws:lambda:eu-west-2:410797082306:layer:instana-python:61
eu-west-3 arn:aws:lambda:eu-west-3:410797082306:layer:instana-python:61
il-central-1 arn:aws:lambda:il-central-1:410797082306:layer:instana-python:61
me-central-1 arn:aws:lambda:me-central-1:410797082306:layer:instana-python:61
me-south-1 arn:aws:lambda:me-south-1:410797082306:layer:instana-python:61
sa-east-1 arn:aws:lambda:sa-east-1:410797082306:layer:instana-python:61
us-east-1 arn:aws:lambda:us-east-1:410797082306:layer:instana-python:61
us-east-2 arn:aws:lambda:us-east-2:410797082306:layer:instana-python:61
us-west-1 arn:aws:lambda:us-west-1:410797082306:layer:instana-python:61
us-west-2 arn:aws:lambda:us-west-2:410797082306:layer:instana-python:61

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.