小编DJe*_*son的帖子

AWS Lambda Python 3.7运行时异常日志记录

使用Python 3.7运行时抛出的未处理异常似乎没有像在Python 3.6中那样记录到CloudWatch.如何在Python 3.7中设置记录器来捕获此信息?

也发布在AWS论坛上

复制:

1.像这样创建一个lambda函数:

import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, context):
logger.info("This shows fine")
raise Exception("I failed")  
Run Code Online (Sandbox Code Playgroud)

2.使用Python 3.6运行时运行此函数

START RequestId: a2b6038b-0e5f-11e9-9226-9dfc35a22dcc Version: $LATEST
[INFO]  2019-01-02T07:25:52.797Z    a2b6038b-0e5f-11e9-9226-9dfc35a22dcc //This shows fine
 I failed: Exception
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 9, in lambda_handler
        raise Exception("I failed")
Exception: I failed

END RequestId: a2b6038b-0e5f-11e9-9226-9dfc35a22dcc
REPORT RequestId: a2b6038b-0e5f-11e9-9226-9dfc35a22dcc  Duration: 1.12 ms   Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 21 MB
Run Code Online (Sandbox Code Playgroud)

2.切换到Python 3.7运行时并再次运行...没有堆栈跟踪

    START …
Run Code Online (Sandbox Code Playgroud)

python python-3.x amazon-cloudwatch aws-lambda

13
推荐指数
1
解决办法
1124
查看次数