Cloudwatch 日志 "AND NOT" 搜索

Cloudwatch logs "AND NOT" search

我在 Cloudwatch 日志事件中搜索符合以下条件的错误:

?"error" ?"ERROR" ?"Error:"

如何从结果中排除特定字词?比如我不关心specific_error,我怎么能指定不在上面匹配呢?

我希望能够做类似的事情:

(?"error" AND -"specific_error") ?"ERROR" ?"Error:"

在 CloudWatch 控制台中,这可以通过在您希望排除的术语之前的 - 操作数来完成:

"error" -"something minor happened"

这是来自 AWS docs for "Matching terms in log events".

同样,使用 aws logs tail,您可以将其传递给 --filter-pattern 参数:

$ aws logs tail --format short /aws/lambda/my_lambda --filter-pattern '"error" -"something minor happened"' --since 3h

2021-07-09T19:28:47 error:   something bad happened
2021-07-09T19:28:51 error:   something bad happened
2021-07-09T19:29:52 error:   something REALLY bad happened
2021-07-09T19:30:15 error:   something CATASTROPHIC happened! Aiee!
2021-07-09T19:30:36 error:   something bad happened