一个 lambda 可以有一个成功或错误的结果。
我想查看错误的 lambda 日志。我正在尝试通过 CloudWatch Insights 查询来做到这一点。
我怎样才能做到这一点?
一个 lambda 可以有一个成功或错误的结果。
我想查看错误的 lambda 日志。我正在尝试通过 CloudWatch Insights 查询来做到这一点。
我怎样才能做到这一点?
如果有人来这里寻找解决方案,这就是我使用的:
filter @message like /(?i)(Exception|error|fail)/| fields @timestamp, @message | sort @timestamp desc | limit 20
我使用以下查询来获取答案中提到的查询未涵盖的那些错误,并且我只能在监控仪表板中看到失败。
fields @timestamp, @message
| sort @timestamp desc
| filter @message not like 'INFO'
| filter @message not like 'REPORT'
| filter @message not like 'END'
| filter @message not like 'START'
| limit 20
这是此查询涵盖的一些示例
暂停
@ingestionTime
1600997135683
@log
060558051165:/aws/lambda/prod-
@logStream
2020/09/25/[$LATEST]abc
@message
2020-09-25T01:25:35.623Z d0801056-abc-595a-b67d-47b14d3e9a20 Task timed out after 30.03 seconds
@requestId
d0801056-abc-595a-b67d-47b14d3e9a20
@timestamp
1600997135623
创新错误
@ingestionTime
1600996797947
@log
060558051165:/aws/lambda/prod-****
@logStream
2020/09/25/[$LATEST]123
@message
2020-09-25T01:19:48.940Z 7af13cdc-74fb-5986-ad6b-6b3b33266425 ERROR Invoke Error {"errorType":"Error","errorMessage":"QueueProcessor 4 messages failed processing","stack":["Error:QueueProcessor 4 messages failed processing"," at Runtime.handler (/var/task/lambda/abc.js:25986:11)"," at process._tickCallback (internal/process/next_tick.js:68:7)"]}
@requestId
7af13cdc-74fb-5986-ad6b-6b3b33266425
@timestamp
1600996788940
errorMessage
QueueProcessor 4 messages failed processing
errorType
Error
stack.0
Error: QueueProcessor 4 messages failed processing
stack.1
at Runtime.handler (/var/task/lambda/abcBroadcast.js:25986:11)
stack.2
at process._tickCallback (internal/process/next_tick.js:68:7)
节点运行时的另一个示例
Value
@ingestionTime
1600996891752
@log
060558051165:/aws/lambda/prod-
@logStream
2020/09/24/[$LATEST]abc
@message
2020-09-25T01:21:31.213Z 32879c8c-abcd-5223-98f9-cb6b3a192f7c ERROR (node:6) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
@requestId
32879c8c-7242-5223-abcd-cb6b3a192f7c
@timestamp
1600996891214
您可以在 CloudWatch Logs Insights 中运行以下查询。
filter @type = "REPORT"
| stats max(@memorySize / 1000 / 1000) as provisonedMemoryMB,
min(@maxMemoryUsed / 1000 / 1000) as smallestMemoryRequestMB,
avg(@maxMemoryUsed / 1000 / 1000) as avgMemoryUsedMB,
max(@maxMemoryUsed / 1000 / 1000) as maxMemoryUsedMB,
provisonedMemoryMB - maxMemoryUsedMB as overProvisionedMB
如果有人在寻找如何搜索错误或登录AWS Log insights
,可以使用此查询进行搜索:
fields @timestamp, @message
| filter @message like /text to search/
| sort @timestamp desc
| limit 20
实际上,只需在查询编辑器中选择log group(s)
并添加一个新行| filter @message like /text to search/
就足够了。其余的都是默认的。
另外,请记住配置搜索历史的时间跨度,以防找不到相关结果。默认情况下,它只搜索最后一个1h
.
在您的控制台中,导航到您的 lambda 配置页面。在左上角,单击Monitoring
,然后View logs in CloudWatch
在右侧。