繁体   English   中英

CloudWatch Logs Insights 在日志消息中显示来自 Json 的文件

[英]CloudWatch Logs Insights display a filed from the Json in the log message

这是我来自 AWS API 网关的日志条目:(8d036972-0445) 转换前的方法请求正文:{"TransactionAmount":225.00,"OrderID":"1545623982","PayInfo":{"Method":"ec"," TransactionAmount":225.00},"CFeeProcess":0}

我想编写一个 CloudWatch Logs Insights 查询,它可以显示第一个括号中的 AWS 请求 ID 和 json 中的订单 ID。

我可以通过解析消息来获取 AWS 请求 ID。 如何获取 OrderID json 字段?

任何帮助是极大的赞赏。

| parse @message "(*)  Method request body before transformations: *" as awsReqId,JsonBody
#| filter OrderID = "1545623982" This did not work
| display awsReqId,OrderID
| limit 20


您可以通过两个解析步骤来完成,如下所示:

fields @message
| parse @message "(*) Method request body before transformations: *" as awsReqId, JsonBody
| parse JsonBody "\"OrderID\":\"*\"" as OrderId
| filter OrderID = "1545623982"
| display awsReqId,OrderID
| limit 20

编辑:实际上,你这样做的方式也应该有效。 我认为它不起作用,因为括号和此处的单词 Method (*) Method之间有 2 个空格字符。 尝试删除 1 个空格。

暂无
暂无

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

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