aws_logs_query
Run a CloudWatch Logs Insights query and get results in one call, replacing manual start, poll, and status interpretation steps.
Instructions
Run a CloudWatch Logs Insights query and wait for it to finish -- StartQuery, poll GetQueryResults until the query reaches a terminal status, return the rows -- in ONE call, replacing the three-step start/poll/interpret-status dance you would otherwise write with aws_call. logGroupNames takes 1-50 bare group names ('/aws/lambda/my-fn'); a log-group ARN is accepted and its NAME extracted, which DISCARDS the ARN's account, so a cross-account ARN queries the same-named group in your own account -- real cross-account queries need logGroupIdentifiers, which this tool does not send. queryString is Logs Insights QL, e.g. 'fields @timestamp, @message | filter @message like /ERROR/ | sort @timestamp desc | limit 20' or 'stats count(*) by bin(5m)'. startTime/endTime take the same vocabulary as aws_logs_tail and aws_metrics_query -- relative shorthand ('15m', '1h', '1d', '1w'), 'now', or ISO 8601 with an explicit offset -- defaulting to the last hour, and the window is capped at 90 days. Returns {queryId, status, rows, rowCount, fields, statistics, truncated, ...}: rows are FLATTENED from the API's [{field, value}] pairs into plain objects, so a row reads {'@timestamp': '...', '@message': '...', '@ptr': '...'}. statistics.recordsMatched counts everything the query matched and can be far larger than rowCount when limit (default 1000, max 10000) clipped the result -- truncated is true when it did. BILLING: Insights charges by the uncompressed bytes SCANNED, so a wide window across many log groups costs money whether or not anything matches; narrow the window and add a filter before widening either. Waits up to maxWaitMs (default 120000, max 900000) and reports one progress update per poll; on timeout or client cancellation the query is NEVER stopped -- it keeps running and the error hands back queryId, whose results stay retrievable for 7 days. For plain 'show me recent log lines' with no aggregation, aws_logs_tail is cheaper and simpler.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum rows the query RETURNS (it still scans, and bills for, the whole window). Default 1000. StartQuery's own ceiling is 100000, but a single GetQueryResults call returns at most 10000 rows and the remainder needs GetQueryResults pagination this tool does not use, so 10000 is the cap here. Check 'truncated' and 'statistics.recordsMatched' to see whether more matched than came back. | |
| region | No | Override session region for this call. | |
| endTime | No | Same forms as startTime: relative shorthand, 'now', or ISO 8601 with an explicit offset. Default 'now'. | |
| profile | No | Override session profile for this call. | |
| maxWaitMs | No | Total time to wait for the query, in ms (range 1000-900000). Default 120000. On timeout the query is NOT stopped -- the error returns the queryId and results stay retrievable for 7 days. | |
| startTime | No | Relative shorthand ('15m', '1h', '1d', '1w'), 'now', or an ISO 8601 timestamp with an explicit offset ('2026-05-16T10:00:00Z', '2026-05-16T10:00:00-04:00'). A date-only '2026-05-16' is read as UTC midnight; an offset-less date-time is rejected (it would resolve in the server host's local zone). A bare number like '5' is rejected -- write '5m'. Default '1h'. The window may not exceed 90 days. | |
| timeoutMs | No | Timeout for each individual aws CLI call, in ms. Default 60000. Bounds one start-query or one get-query-results, not the whole wait -- that is maxWaitMs. | |
| queryString | Yes | CloudWatch Logs Insights query, max 10000 chars. E.g. 'fields @timestamp, @message | filter @message like /ERROR/ | sort @timestamp desc | limit 20', or 'stats count(*) by bin(5m)'. | |
| logGroupNames | Yes | 1-50 log group names, e.g. ['/aws/lambda/my-fn'] -- StartQuery caps a query at 50. A full log-group ARN is accepted and its name extracted; that discards the ARN's account, so a cross-account ARN queries the same-named group in YOUR account. | |
| queryLanguage | No | Query language. Default CWLI (Logs Insights QL -- what the queryString examples use). 'PPL' is OpenSearch Piped Processing Language. OpenSearch SQL is deliberately not offered: it expects the log groups named INSIDE the query string rather than passed alongside it, which contradicts this tool's required logGroupNames -- use aws_call for SQL. | |
| pollIntervalMs | No | Delay between GetQueryResults polls, in ms (range 500-30000). Default 2000. The floor keeps one call inside the 10/sec account quota for this API. |