AWS Lambda Container Image (Python)

You can also add Sentry to your Container Image. To import Sentry's Layer Image, add the following to your Dockerfile:

Copied
COPY --from=public.ecr.aws/sentry/sentry-python-serverless-sdk:<VERSION> /opt/ /opt

Replace VERSION with a specific version number (for example, 6). You can see a complete list of available versions in Sentry's Amazon ECR repository.

Function Configuration

Set your image’s CMD value to the Sentry Handler:

Copied
CMD ["sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler"]

Also, set the following environment variables in AWS:

  • Set SENTRY_INITIAL_HANDLER to the path of your function handler
  • Set SENTRY_DSN to your Sentry DSN
  • Set SENTRY_TRACES_SAMPLE_RATE to your preferred sampling rate for transactions

Alternatively, you can also set the environment variables in the Dockerfile:

Copied
ENV SENTRY_INITIAL_HANDLER="<PATH_TO_FUNCTION_HANDLER>"
ENV SENTRY_DSN="https://examplePublicKey@o0.ingest.sentry.io/0"
ENV SENTRY_TRACES_SAMPLE_RATE="1.0"