简体   繁体   English

如何在多个 AWS Cloudwatch 日志流中查找 Python lambda function 的错误日志?

[英]How do I find error logs for my Python lambda function across many AWS Cloudwatch log streams?

Let's say I have log group /aws/lambda/backend , which tracks logs of my Python lambda function.假设我有日志组/aws/lambda/backend ,它跟踪我的 Python lambda function 的日志。 I want to debug common issues, like exceptions and time outs, and find related log entries.我想调试常见问题,例如异常和超时,并查找相关的日志条目。

But the function has a lot of concurrent traffic, so there are many log streams in the log group.但是function的并发流量很大,所以日志组的日志流很多。 How do I find the log entries across all logs without visiting each individual log stream and perform the search?如何在不访问每个单独的日志 stream 的情况下找到所有日志中的日志条目并执行搜索?

This is possible by using Logs Insights , which uses a query language to analyze logs in a log group.这可以通过使用Logs Insights来实现,它使用查询语言来分析日志组中的日志。

For common Python function errors, I find this query useful:对于常见的 Python function 错误,我发现此查询很有用:

fields @timestamp, @message, @logStream
| filter @message like /(?i)Exception|Error|Traceback|Timed out/
| sort @timestamp desc
| limit 20

This will return log queries and links to log groups to places, where exceptions or timeouts happened.这将返回日志查询和日志组链接到发生异常或超时的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM