ExitAmazon CloudWatch: Logs Insights queries1 / 7
Explanation

Separate scan scope from result size

How Logs Insights parsing, filtering, aggregation, and multi-log-group queries correlate security events while controlling query scope and scan cost. · advanced

CloudWatch Logs Insights QL queries events already stored in CloudWatch Logs. Start by selecting the relevant log groups and the smallest useful time range. Those choices bound the search before parsing or aggregation. In the console, select the groups directly; programmatic queries can use SOURCE to select groups by criteria such as name prefix and account. SOURCE is not supported in the console query editor.

Scan volume and result size are different. An ordinary filter can discard most matching events without avoiding the underlying scan. Similarly, fields, stats, and a final limit can produce a tiny result from a large scan. Do not treat a short result table as evidence of a cheap query; inspect the query's scanned-data statistics.

Field indexes can reduce scanning for supported queries over indexed fields. Equality and IN filters can benefit from an existing field index; like and regular-expression matching do not use that index optimization. A field extracted from free text during the query does not become an ingestion-time index. Narrow scope first, use eligible indexed predicates where available, and stop queries that are no longer needed.

ControlMain effectScan-cost implication
Groups and time rangeBound candidate eventsDirect scope control
Eligible indexed filterSkip indexed dataCan reduce scanning
Ordinary filterRemove result eventsNo guaranteed scan reduction
Stats and final limitSummarize or trim outputSmall output proves little