Query and Filter CloudWatch Logs with Insights
Use CloudWatch Logs Insights to search, filter, and analyze log data across log groups with powerful query syntax for rapid debugging.
Prerequisites
- -AWS CLI v2 installed and configured
- -Application writing logs to CloudWatch Logs
Steps
List available log groups
Browse available CloudWatch log groups to identify where your application or service writes its logs.
Use --log-group-name-prefix to filter results, for example --log-group-name-prefix /aws/lambda/ to see only Lambda function logs.
Tail logs in real time
Stream live log events from a log group to your terminal for real-time debugging.
The --since flag accepts relative times like 5m, 1h, or 1d as well as absolute ISO 8601 timestamps.
Start a Logs Insights query
Run a structured query to find error patterns in your logs over a specific time range.
Logs Insights queries are asynchronous. The command returns a queryId that you use to fetch results in the next step.
Get query results
Retrieve the results of a previously started Logs Insights query using the query ID.
Check the status field in the response. If it shows 'Running', wait a few seconds and retry. Results are only available when status is 'Complete'.
Analyze patterns with stats
Use the stats command to aggregate log data and identify trends like error rates or latency distributions.
Lambda REPORT lines contain execution duration, memory used, and billed duration. Use @type = REPORT to filter for these summary lines.
Full Script
FAQ
Discussion
Loading comments...