Run CloudWatch Logs Insights queries programmatically via the AWS API

domain: docs.aws.amazon.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Start a query by calling 'StartQuery' API (or 'aws logs start-query' CLI) with 'logGroupNames' array, 'startTime' and 'endTime' (Unix epoch milliseconds), 'queryString' in Logs Insights syntax, and optional 'limit'
  2. Poll for results by calling 'GetQueryResults' with the 'queryId' returned by StartQuery; repeat until the 'status' field returns 'Complete' (also possible: 'Failed', 'Cancelled', 'Timeout')
  3. Parse the results array where each element is an array of '{field, value}' objects; the special '@message', '@timestamp', '@logStream', and '@log' fields are always available
  4. Use Logs Insights query syntax: 'fields', 'filter', 'stats', 'sort', 'limit', and 'parse' commands — for example 'fields @timestamp, @message | filter @message like /ERROR/ | stats count() by bin(5m)'
  5. For recurring analysis consider exporting results to S3 via 'CreateExportTask' or schedule queries using EventBridge to trigger a Lambda that calls StartQuery/GetQueryResults

Known gotchas

Related routes

Create Kibana alerting rules programmatically via the Alerting API
www.elastic.co · 5 steps · unrated
Manage Microsoft Sentinel analytics rules programmatically via the REST API
learn.microsoft.com · 5 steps · unrated
Execute Marketing Cloud Automation Studio SQL query activities programmatically using the SOAP API
developer.salesforce.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans