AWS Lambda
See every invocation of your AWS Lambda function (how long it ran, whether it succeeded, and any errors it raised) as a trace (the full journey of one invocation, made of nested spans, where each span is one unit of work with a name, a start, and a duration) in Logfire.
- Each invocation of your handler as a span, with its duration and status
- Any errors raised while the function ran
- Any instrumented work inside the handler (database queries, HTTP calls) as nested spans
You’ll need a Logfire project. Open Add data in your project (top navigation) and follow the
setup for your language: it signs your machine in with logfire auth (a browser sign-in, no token
to copy) and, for production or other languages, creates a write token (the credential your app
uses to send data). New to Logfire? Start with Getting Started.
Install logfire with the aws-lambda extra:
pip install 'logfire[aws-lambda]'
uv add 'logfire[aws-lambda]'
Call logfire.configure() to connect to your project, then
logfire.instrument_aws_lambda() with your handler (after
the handler is defined) to record every invocation:
import logfire
logfire.configure() # (1)
def handler(event, context):
return 'Hello from Lambda'
logfire.instrument_aws_lambda(handler) Set the LOGFIRE_TOKEN environment variable on your Lambda function's configuration in the AWS
console so configure() can find your write token.
Invoke your function (for example, from the AWS console or with a test event), then open the Live view. Within a few seconds you’ll see a span for the invocation, with its duration and status.
Not seeing your invocations in Logfire? Check that logfire.configure() ran before
instrument_aws_lambda(), that the LOGFIRE_TOKEN environment variable is set on the Lambda function’s
configuration, and that you passed your handler to instrument_aws_lambda() exactly once.
logfire.instrument_aws_lambda(): the Logfire API reference.- OpenTelemetry AWS Lambda instrumentation: the underlying package.