cloudwatch-logs-insights-query

Write and validate AWS CloudWatch Logs Insights QL queries from raw log samples.

Updated May 20, 2026
One-click install
npx skills add https://github.com/TeXmeijin/agent-skills --skill cloudwatch-logs-insights-query-texmeijin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cloudwatch-logs-insights-query
Source: https://github.com/TeXmeijin/agent-skills/tree/main/.apm/skills/cloudwatch-logs-insights-query
Command: npx skills add https://github.com/TeXmeijin/agent-skills --skill cloudwatch-logs-insights-query-texmeijin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing CloudWatch Logs Insights queries by hand often leads to syntax errors, invalid field references, and commands that silently fail on Infrequent Access log classes. This Skill turns raw log samples and requirements into correct, runnable Logs Insights QL queries with strict validation against AWS syntax rules. ## Core Features & Use Cases - Query construction from log samples: Maps existing fields or extracts new ones with parse (glob or regex), then builds fields, filter, stats, sort, and limit clauses in the correct order. - Syntax and constraint validation: Enforces rules such as the two-stats limit, backtick escaping for special field names, and log class restrictions (pattern, diff, filterIndex, unmask unsupported on Infrequent Access). - Ready-to-adapt query patterns: Includes reference patterns for error trends, p95 latency by route, top endpoints, deduplication, and two-stage stats rollups. - Use Case: Given a JSON application log sample, generate a query that computes p95 latency per endpoint over 5-minute bins, with all inferred field mappings documented. ## Quick Start Ask the agent to build a CloudWatch Logs Insights query from your pasted log sample, specifying the log class, time range, and desired aggregation.

Frequently Asked Questions about cloudwatch-logs-insights-query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a CloudWatch Logs Insights query from a log sample?

Provide a raw log sample including @message, the log class, and your desired output. Fields that already exist are used directly; missing fields are extracted with parse using glob or regex, then filter, stats, sort, and limit clauses are chained with pipes.

How to extract fields from JSON logs in CloudWatch Logs Insights?

Use the parse command with a named-capture regex, for example parse @message /status=(?<status>\d{3})/. Nested JSON requires regex because glob parsing does not support nested structures, and flattened JSON is limited to 200 fields.

Which CloudWatch Logs Insights commands are unsupported on Infrequent Access logs?

The pattern, diff, filterIndex, and unmask commands are not supported on the Infrequent Access log class. Standard class logs support all commands, so queries targeting Infrequent Access must avoid those four.

Why does my CloudWatch Logs Insights query fail with two stats commands?

Logs Insights allows at most two stats commands per query, and sort and limit must come after the second stats. Also, after the first stats only the fields it defines remain available, so carry a timestamp field forward if you need bin() later.

How do I handle field names with special characters in Logs Insights?

Wrap any field name containing non-alphanumeric characters other than @ or . in backticks, for example `foo-bar`. This applies in fields, filter, parse, stats, and sort clauses.