Prompt
Why are my CloudWatch Logs queries taking forever?
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
CloudWatch Logs queries are usually slow for a few common reasons:
-
You’re scanning too much data
- Queries are billed and executed based on how much log data they scan.
- If you search a large log group, a long time range, or many log groups, it can take a while.
-
Your query isn’t selective enough
- Using broad filters like
fields *,filter @message like /error/, or searching without narrowing by service, requestId, or log stream makes CloudWatch inspect lots of records.
- Using broad filters like
-
High log volume / large retention
- Very active log groups or long retention periods mean more data to process.
- Old data can still be in scope if your time range is wide.
-
Too many log groups or cross-account sources
- Querying multiple log groups at once, especially across accounts/regions, adds overhead.
-
Complex parsing or aggregation
- Heavy use of
parse,stats,sort,dedup, or multiple regex operations can slow things down. sorton large result sets is especially expensive.
- Heavy use of
-
Results are limited by service-side processing
- CloudWatch Logs Insights is an interactive analytics service, not a low-latency indexed search engine.
- Some queries simply take longer depending on the dataset.
How to speed them up
- Narrow the time range as much as possible.
- Query fewer log groups.
- Filter early using specific fields like
@logStream,requestId,service,level, ortraceId. - Avoid broad regex unless necessary.
- Reduce sorting/aggregation on large datasets.
- Use structured logs (JSON) so you can filter by fields instead of parsing message text.
- If you repeatedly query the same data, consider exporting to S3 + Athena, or using a more search-oriented solution like OpenSearch.
If you want, paste one of your slow queries and I can suggest concrete changes to make it faster.