AWS Lambda Supportedit

This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

Incorporating Elastic APM into your AWS Lambda functions is easy!


First, you need to add elastic-apm as a dependency for your python function. Depending on your deployment strategy, this could be as easy as adding elastic-apm to your requirements.txt file, or installing it in the directory you plan to deploy using pip:

$ pip install -t <target_dir> elastic-apm

You should also add the Elastic AWS Lambda Extension layer to your function.


Once the library is included as a dependency in your function, you must import the capture_serverless decorator and apply it to your handler:

from elasticapm import capture_serverless

def handler(event, context):
    return {"statusCode": r.status_code, "body": "Success!"}

The agent uses environment variables for configuration

ELASTIC_APM_SECRET_TOKEN=<apm-server token>

Note that the above configuration assumes you’re using the Elastic Lambda Extension. The agent will automatically send data to the extension at localhost, and the extension will then send to the APM Server as specified with ELASTIC_APM_LAMBDA_APM_SERVER.


Once the agent is installed and working, spans will be captured for supported technologies. You can also use capture_span to capture custom spans, and you can retrieve the Client object for capturing exceptions/messages using get_client.