Safe Init is a Python library that enhances AWS Lambda functions with advanced error handling, logging, monitoring, and resilience features. Version 1.4.0 (released 2025-04-02) adds automatic JSON serialization checks and uses uv for dependency management. The library requires Python <3.12 and >=3.11, and integrates with Sentry, Slack, AWS Secrets Manager, and Redis.
pip install safe-initVerified import paths — ran on the pinned version, not inferred.
Wrap your Lambda handler with the @safe_init.lambda_handler decorator to automatically capture errors and report to Sentry.
Use safe_init.set_slack_webhook() and safe_init.set_custom_logger() via context variables instead of monkey patching.
Ensure your Lambda returns JSON-serializable objects, or configure the check if you need different behavior.
Create a .env.json file in your Lambda deployment package with key-value pairs.
Use Python 3.11 runtime in AWS Lambda.
Ensure your secret ARN either includes the full ARN or only the name without prefix.