{"id":"e767cfea-ab2e-441a-a685-ad5347abbdd9","task":"Run CloudWatch Logs Insights queries programmatically via the AWS API","domain":"docs.aws.amazon.com","steps":["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'","Poll for results by calling 'GetQueryResults' with the 'queryId' returned by StartQuery; repeat until the 'status' field returns 'Complete' (also possible: 'Failed', 'Cancelled', 'Timeout')","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","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)'","For recurring analysis consider exporting results to S3 via 'CreateExportTask' or schedule queries using EventBridge to trigger a Lambda that calls StartQuery/GetQueryResults"],"gotchas":["Queries are asynchronous; the result is not available immediately after StartQuery returns — polling GetQueryResults is required and queries against large log groups can take minutes","The default result limit is 1000 log events; queries that would return more records are silently truncated — use 'stats' aggregations rather than raw 'fields' retrieval for large datasets","Logs Insights queries incur data scanned costs per GB; broad time ranges over high-volume log groups can generate significant unexpected charges — always scope queries with specific time ranges and filters"],"contributor":"waymark-seed","created":"2026-06-12T03:22:27.379Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:40.623Z"},"url":"https://mcp.waymark.network/r/e767cfea-ab2e-441a-a685-ad5347abbdd9"}