How do I override the sys.excepthook in a Lambda Python container?

0

I want to override the excepthook so I can generate structured logging of errors without wrapping a try-catch block around everything.

If you try this barebones example, it fails:

import sys

def log_uncaught_exception_hook(exc_type, exc_value, exc_traceback):
    print("custom exception hook triggerd")

sys.excepthook = log_uncaught_exception_hook

def lambda_handler(event, context):
    raise(Exception("asdf"))

I find it odd that awslabs recently released a feature to override the excepthook in the AWS Powertools for Lambda package. Likewise when using said feature in a lambda environment (and not on your local machine) it fails.

I tried looking more into this issue, but it seems like the original AWS forum post about this has been deleted with no replacement.

Please tell me why I can't override the excepthook in a python lambda

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠