1
votes

I want to fetch the 100 latest log events from CloudWatch using its API (AWS Lambda logs).

I have found 2 solutions:

  • GetLogEvents: allows to fetch the latest 100 events (using startFromHead), but only for a specific stream (which doesn't work with Lambda, I want to read from all streams)
  • FilterLogEvents: allows to collect from any stream in the log group, but doesn't let us sort logs by date to fetch the latest events

How can I fetch the 100 latest events from a whole log group?

1

1 Answers

2
votes

You can use the StartQuery API instead:

fields @timestamp, @message | sort @timestamp desc | limit 100