gpt4 book ai didi

python - 如何在 AWS Lambda 上使用 Python 从 Zappa 获取堆栈跟踪

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:56 25 4
gpt4 key购买 nike

我正在使用 Zappa 框架 https://github.com/Miserlou/Zappa在 AWS Lambda 上使用 Python 和 Flask。当它引发异常时,它会出现在 CloudWatch 日志中,但我无法辨认。但是,在调试构建中,我确实得到了从 HTTP GET 返回的正常 Flask 堆栈跟踪。

我的问题是如何在日志中/从生产代码中获取合理的 (Flask) 堆栈跟踪?当生产中出现异常时,我所拥有的只是日志消息。

来自 HTTP GET 的良好堆栈跟踪:

Traceback (most recent call last):
File "/var/task/handler.py", line 96, in handler
response = Response.from_app(app, environ)
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/Werkzeug/werkzeug/wrappers.py", line 865, in from_app
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/Werkzeug/werkzeug/wrappers.py", line 57, in _run_wsgi_app
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/Werkzeug/werkzeug/test.py", line 871, in run_wsgi_app
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/zappa/zappa/middleware.py", line 78, in __call__
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1836, in __call__
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1820, in wsgi_app
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 271, in error_router
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1403, in handle_exception
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 268, in error_router
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1817, in wsgi_app
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1477, in full_dispatch_request
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 271, in error_router
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1381, in handle_user_exception
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 268, in error_router
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1475, in full_dispatch_request
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1461, in dispatch_request
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 477, in wrapper
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/views.py", line 84, in view
File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 587, in dispatch_request
File "/Users/notacat/src/aws-lambda/zappa/controllers/error_controller.py", line 15, in get
TestError: 'This is a test error'

难以理解 CloudWatch 日志中的堆栈跟踪:

...Rlc3RFcnJvcjogJ1RoaXMgaXMgYSB0ZXN0IGVycm9yJzxiciAvPjwvcHJlPg==: 
Exception Traceback (most recent call last):
File "/var/task/handler.py", line 161, in lambda_handler return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 55, in lambda_handler return cls().handler(event, context)
File "/var/task/handler.py", line 155, in handler raise Exception(exception)
Exception: PCFET0NUWVBFIGh0bWw+NTAwLiBGcm9tIFphcHBhOiA8cHJlPidUaGlzIGl...

最佳答案

这看起来像是一个老问题,但我使用的是 Zappa 0.45.1,当通过 CloudWatch AWS 终端和使用 zappa tail 发生错误时,我可以看到我的 python 堆栈跟踪提供 CloudWatch 日志和一些附加信息。

关于python - 如何在 AWS Lambda 上使用 Python 从 Zappa 获取堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38548173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com