---
title: "AWS Lambda tracing with the Python SDK"
description: "Sentry's Python SDK 3.0 continues traces across Lambda Invoke calls and links SQS and SNS messages to their producers."
url: "https://blog.sentry.io/sentry-python-aws-lambda/"
canonical_url: "https://blog.sentry.io/sentry-python-aws-lambda/"
authors: ["Alexander Alderman Webb"]
published: "2026-11-30"
category: "Product Updates"
---

# AWS Lambda tracing with the Python SDK

With version 3.0 of the Python SDK, we now connect Lambda invocations to the client and link how data flows through your AWS services. This post focuses on trace-connectedness (improved in 3.0). Tracing AWS calls with Sentry already surfaces problems like timeouts and cold starts.

## Lambda Invoke propagation

Before 3.0, the trace was only connected when a Lambda function was triggered through an HTTP endpoint, where trace headers arrive in the event. Now it’s also connected when you call the Lambda Invoke API synchronously, for example with `boto3.client("lambda").invoke()`.

Trace metadata is picked up from custom client context passed to a `RequestResponse` Lambda invocation. The context is provided with Lambda invocations through `boto3`. This happens in the SDK’s `Boto3Integration`, which is enabled by default. The Lambda execution span continues the incoming trace based on these values.

In the image below, you can see a Lambda function invoked inside an HTTP handler. The trace continues from the handler to the Lambda function.

![Sentry trace waterfall with a backend handler that synchronously invokes a Lambda function.](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-1.D2UWxuHs.png&w=1200&q=100)

If you can’t rely on our `boto3` instrumentation, manually put the `sentry-trace` and `baggage` values under `custom` in the client context. For example, this is the case if the caller isn’t written in Python. The snippet below shows how to add the trace metadata in Python:

```python
import base64
import json

import boto3
import sentry_sdk

client_context = {
    "custom": {
        "sentry-trace": sentry_sdk.get_traceparent(),
        "baggage": sentry_sdk.get_baggage(),
    }
}

boto3.client("lambda").invoke(
    FunctionName=...,
    ClientContext=base64.b64encode(json.dumps(client_context).encode()).decode(),
    Payload=...,
)
```

The SDK’s `AwsLambdaIntegration` reads these values on the other side, so there’s nothing to add in the Lambda function.

## Tracing across SQS and SNS

You can also link together publishers and consumers in Amazon Simple Queue Service (SQS) queues and Amazon Simple Notification Service (SNS) topics. Pass trace metadata as message attributes, and it’s automatically attached to the Python SDK’s span tracing the consumer. The producer’s trace is then linked to the consumer’s trace.

![Sentry trace waterfall for a Lambda function consuming an SQS message, with the queue.process span linked to the producer's trace.](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-3.BE_WrQ24.png&w=1200&q=100)

As with Lambda Invoke, the SDK has you covered when you publish to a queue or topic with `boto3` and the SDK’s `Boto3Integration` is active.

You can also pass the attributes yourself. This is how it looks in Python:

```python
import boto3
import sentry_sdk

boto3.client("sqs").send_message(
    QueueUrl=...,
    MessageBody=...,
    MessageAttributes={
        "sentry-trace": {
            "DataType": "String",
            "StringValue": sentry_sdk.get_traceparent(),
        },
        "baggage": {
            "DataType": "String",
            "StringValue": sentry_sdk.get_baggage(),
        },
    },
)
```

## Amazon Bedrock calls are traced too

Bedrock `Converse` and `ConverseStream` calls create spans. These are rich GenAI spans featuring model inputs, model outputs, and token usage, among other information. Here’s how it looks in Sentry.

![Sentry conversation view of two successive Bedrock calls to fix a flaky test.](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-2.B-PmA_Yt.png&w=1200&q=100)

Learn more on the [Conversations docs page](https://docs.sentry.io/product/agents/conversations/).

## Get started

Add `sentry-sdk` to your dependencies:

```bash
uv add "sentry-sdk>=3.0.0"
```

Then initialize the SDK with `AwsLambdaIntegration` in your function:

```python
import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    traces_sample_rate=1.0,
    integrations=[
        AwsLambdaIntegration(),
    ],
)


def lambda_handler(event, context):
    ...
```

`Boto3Integration` is enabled automatically when `boto3` is installed, so all `boto3` requests are traced.

Upgrading from 2.x? See the [Python SDK 2.x to 3.x migration guide](https://docs.sentry.io/platforms/python/migration/2.x-to-3.x).

See the [AWS Lambda](https://docs.sentry.io/platforms/python/integrations/aws-lambda/) and [Boto3](https://docs.sentry.io/platforms/python/integrations/boto3/) integration docs for more information.

If something doesn’t work or is missing, [open an issue on the sentry-python GitHub repository](https://github.com/getsentry/sentry-python/issues).
