15

is there a way to paginate AWS CloudWatch Logs Insights? Thank you.

I was thinking something like below but that doesn't work

fields @message | page 2 | limit 20

EDIT:

I am currently accessing the logs via the Logs Insight enter image description here

In my app, I am accessing it via AWS.Logger.Serilog. But I can move to a different approach (e.g. raw API call) if that would allow me to paginate the logs result.

I have tried browsing through the AWS CloudWatch documentation, google, and stack overflow. The problem I'm trying to overcome is how to paginate the logs so it won't load all the logs given a query.

Jan Paolo Go
  • 5,842
  • 4
  • 22
  • 50

2 Answers2

0

There's not a native way to do this with the CloudWatch Insights Query Syntax.

You could achieve this in your application logic by using the last element in the current result set's sort field value as a next item token.

For example, your query uses @timestamp as the sort field. To fetch the next page, you could append filter (@timestamp < {value}) to the new query, where {value} is the timestamp of the previous query result's last item.

akerra
  • 1,017
  • 8
  • 18
-1

Filter by timestamp query on AWS Cloudwatch Logs Insights has solution on how to filter on @timestamp on milliseconds even. So you can build pagination with that by doing a

| fields tomillis(@timestamp) as millis
| filter millis < {time_stamp_of_last_returned_log_line} 
JaapH
  • 391
  • 2
  • 6