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
[2023年7月更新]
有一个带有 CLoudwatch 日志洞察的新命令pattern,它在幕后使用 ML 自动将日志数据聚类为模式。
pattern 命令使用 AWS 机器学习算法自动识别日志数据中的模式、聚合相关日志并将数千条日志行汇总为几个易于可视化的分组。模式可帮助客户快速发现新兴趋势、监控已知错误、通过识别频繁发生的日志行等来提高成本可见性。
filter @message like /ERROR/
| pattern @message
根据您的日志记录查看特定错误消息
filter @message like /ERROR/
| parse @message 'Failed to do: *' as cause
| pattern cause
| sort @sampleCount asc
在控制台中,导航到 lambda 的配置页面。单击左上角的
Monitoring
,然后单击右侧的 View logs in CloudWatch
。
您可以在 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