AWS Lambda¶
The logfire.instrument_aws_lambda
function can be used to
instrument AWS Lambda functions to automatically send traces to Logfire.
Installation¶
Install logfire
with the aws-lambda
extra:
pip install 'logfire[aws-lambda]'
uv add 'logfire[aws-lambda]'
rye add logfire -E aws-lambda
poetry add 'logfire[aws-lambda]'
Usage¶
To instrument an AWS Lambda function, call the logfire.instrument_aws_lambda
function after defining
the handler function:
import logfire
logfire.configure() # (1)!
def handler(event, context):
return 'Hello from Lambda'
logfire.instrument_aws_lambda(handler)
- Remember to set the
LOGFIRE_TOKEN
environment variable on your Lambda function configuration.
logfire.instrument_aws_lambda
uses the OpenTelemetry AWS Lambda Instrumentation package,
which you can find more information about here.