jth*_*jth 5 python logging amazon-web-services python-3.x aws-lambda
AWS Lambda provides built-in logging configuration as described here so that log records include timestamp and request ID. Request ID is a UUID for a particular invocation of a Lambda function, so it's important to include it in each log record because it allows the user to query for all log records with a given request ID (using CloudWatch Logs Insights), which allows for retrieving log records from a particular Lambda invocation. (It is not sufficient to simply filter by log stream, as a single log stream can contain logs from multiple invocations if the invocations were run within the same environment, as described here.)
Unfortunately, when a Python AWS Lambda function crashes due to an unhandled exception, the log record for the exception does not include the request ID. The obvious solution is to log unhandled exceptions via the logging module, so that request ID is included in the log record. This appears to be the cleanest solution but it does not work in this case because overriding sys.excepthook does not appear to have any effect within a Lambda environment (here is the only other source I can find that references this fact).
因此,我想知道是否有推荐的方法在 Python AWS Lambda 函数中未处理的异常的日志记录中包含请求 ID?这似乎是一个应该有标准解决方案的问题。try否则,我将用/包围 lambda 处理程序代码,以except记录并重新引发所有未处理的异常。
| 归档时间: |
|
| 查看次数: |
730 次 |
| 最近记录: |