AWS Lambda Layer
You can add Sentry to your AWS Lambda function by adding the Sentry AWS Lambda Layer to your function.
Install The Layer
Navigate to your Lambda function:
Scroll down to the Layers section and click Add a Layer:
Specify an ARN tab as illustrated:
First, set the region and copy the provided ARN value:
Now copy that ARN into the input box:
Configure the Sentry SDK
For Sentry to instrument your Lambda function, you need to change the handler of your function and set the Sentry
Set the Sentry Handler
The Sentry layer will wrap your function handler to initialise the Sentry SDK in your function.
In you Lambda function, scroll to Runtime settings and click Edit:
Note your current Handler and change it to: sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler
:
After saving, open the "Configuration" tab of your Lambda Function and set SENTRY_INITIAL_HANDLER
to the handler you noted before:
Configuration Options
Make sure that SENTRY_DSN
and SENTRY_INITIAL_HANDLER
are set in your environment at minimum. See "Set the Sentry Handler" above for more information.
You can configure Sentry by setting these environment variables for your Lambda function:
SENTRY_INITIAL_HANDLER
: The handler function of your AWS Lambda funtion.SENTRY_DSN
: This is set to the DSN of yourprojectRepresents your service in Sentry and allows you to scope events to a distinct application.SENTRY_TRACES_SAMPLE_RATE
: This sets the sampling rate for transactions.
Verify
Add an error to your function and run it. If everything's working properly, it should be captured and sent to Sentry.io.
Troubleshooting
Error:
"Unable to import module 'lambda_function': urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'. See: https://github.com/urllib3/urllib3/issues/2168"
This error means that you have
urllib3>=2.0
in you dependencies. The Python runtime used in AWS Lambda is not compatible with urllib3 version 2, because it still uses OpenSSL 1.0.Solution: There are two solutions for this error:
- Either use a newer Python runtime for your Lambda function.
urllib3
version 2+ is supported in AWS Lambda from the Python 3.9 Lambda runtime and newer. - Or pin your dependency of urllib3 to
urllib3<1.27
to make it work with the Python runtime 3.7 and 3.8 used in AWS Lambda.
- Either use a newer Python runtime for your Lambda function.
Supported Versions
- Lambda Layer up to Version 63: Python 3.6, 3.7, 3.8, 3.9
- Lambda Layer Version 64+: Python 3.9, 3.10, 3.11
- Lambda Layer Version 77+: Python 3.7, 3.8, 3.9, 3.10, 3.11
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- pypi:sentry-sdk
- Version:
- 1.39.2
- Repository:
- https://github.com/getsentry/sentry-python
- API Documentation:
- https://getsentry.github.io/sentry-python/