
- Fast, interactive, SQL-like queries over log data already in CloudWatch Logs.
- No additional infrastructure required — suitable for troubleshooting, pattern discovery, and ad-hoc performance analysis.
- Optimized for recent, time-series log analysis (for archived S3 logs use Athena; for large-batch processing consider EMR).

Query retention and limits (quick reference)
- Query results retained: 7 days.
- Saved queries per account: up to 1,000.
- Price model: pay-per-scan (billed on volume scanned during queries).
- Query timeout: 15 minutes.
- Result rows: default 1,000, maximum 10,000.
- Select fields —
fields - Restrict events —
filter(do this early to reduce scanned bytes) - Extract fields —
parse(for unstructured logs) - Aggregate & transform —
stats,sort,limit

Automatic fields always available:
@timestamp, @message, @logStream, @log. JSON logs are auto-discovered and do not require parse for already-known fields.
Common query examples
- Top error messages:
- Latency percentile analysis by endpoint:
- Request volume by service, hourly:
=— exact equalitylike— wildcard pattern matching (case-sensitive by default; append/ifor case-insensitive)in— membership in a list- Full regular expressions — use for complex extraction and matches

- Logs that are structured JSON (including nested JSON / JSON Lines) are automatically discovered at query time.
- First queries against a new structure may be slightly slower while discovery occurs. Example JSON log:

- Filter early: put
filterat the top of your pipeline beforeparseorstats. - Target specific log groups: avoid querying all logs unless required.
- Narrow time ranges: start small (e.g., last 1 hour or 7 days) and expand only as needed.
- Sample during development: test query logic on a small time window before wide runs.
- Save reusable queries: reduce ad-hoc rework and accidental scans.

- Embed Logs Insights queries in CloudWatch dashboards for charts and widgets.
- Export query results to CSV for offline analysis.
- Visual charts available: bar, line, stacked area, and other CloudWatch chart types.
- Exported results can feed external tools: Amazon QuickSight, Grafana (including AWS Managed Grafana), or OpenSearch for advanced dashboards.

- Create CloudWatch metric filters from log data and publish metrics to drive alarms.
- Use metric filters + alarms for continuous monitoring. Logs Insights is intended for interactive analysis, not as a primary alerting mechanism.
- There is no native scheduler in the Logs Insights console. For automation, call the Logs Insights APIs and orchestrate with EventBridge or Lambda (example below).

CloudWatch Logs Insights can be invoked programmatically using the CloudWatch Logs APIs (for example,
StartQuery, GetQueryResults, and StopQuery). For scheduled or automated queries, combine StartQuery with EventBridge (or Lambda) to run queries on a schedule and capture results.- Amazon Athena: long-term, large-scale SQL queries over logs archived in S3 (good for scheduled/recurring historic analysis).
- OpenSearch / Elasticsearch: full-text search, complex dashboards, external team access without the AWS Console.
- EMR or other big-data tools: large-scale batch processing or custom analytics pipelines.

- AWS CloudWatch Logs Insights documentation: https://docs.aws.amazon.com/cloudwatch/latest/logs/CWL_QuerySyntax.html
- Amazon Athena: https://aws.amazon.com/athena/
- Amazon OpenSearch Service: https://aws.amazon.com/opensearch-service/
- EventBridge (scheduling): https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html
- CloudWatch Logs APIs (StartQuery, GetQueryResults): https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_StartQuery.html