我需要使用 AWS Cloudwatch 日志洞察从 lambda 查询数据。aws 提供的查询语法没有区别。
仅支持 (count_distinct(fieldname))
参考。https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html
示例数据
列#@timestamp@message
1 2020-02-17T13:33:29.049+07:00 [INFO] 2020 分区键:ABC12345_A_
2 2020-02-17T11:32:29.049+07:00 [INFO] 2020 分区键:ABC12345_B_
3 2020-02-17T11:31:29.049+07:00 [INFO] 2020 分区键:ABC12345_B_
4 2020-02-17T11:30:29.049+07:00 [INFO] 2020 分区键:ABC12345_C_
5 2020-02-17T11:29:29.049+07:00 [INFO] 2020 分区键:ABC12345_A_
预期结果
1 2020-02-17T13:33:29.049+07:00 [INFO] 2020 分区键:ABC12345_A_
2 2020-02-17T11:32:29.049+07:00 [INFO] 2020 分区键:ABC12345_B_
4 2020-02-17T11:30:29.049+07:00 [INFO] 2020 分区键:ABC12345_C_
如果使用正常的 SQL 语法如下所示。
select distinct(uuid) as uuid, max(time) as time from table_name group by uuid order by time desc