"Logs are for reading line by line." Not at scale. A busy application writes millions of log lines a day. Nobody can scroll through that during an incident. You need to search, count and alert on logs, and on AWS that starts with Amazon CloudWatch Logs.
Events, streams and groups
CloudWatch Logs receives logs from many AWS services (Lambda, API Gateway, VPC Flow Logs, CloudTrail and more), from the CloudWatch agent on EC2 instances and on-premises servers, and from your own code through the API.
- A log event is one record: a timestamp and a message.
- A log stream is a sequence of events from one source, such as one instance or one Lambda execution environment.
- A log group holds streams that share the same settings: retention, access control, metric filters and subscriptions.
Settings live on the log group, so name groups by application and environment (/prod/api, /staging/api) and you can manage them consistently.
Retention: the first setting to change
By default, a new log group keeps data forever ("Never expire"), and you pay for that storage every month. Set a retention period on each log group (for example 30 days for debug logs, longer for audit logs), or create an account-level retention policy that applies to all log groups or to a name prefix. There is also a lower-cost Essentials log class (formerly Infrequent Access) for logs you rarely query.
Searching with Logs Insights
CloudWatch Logs Insights queries one or many log groups at once. It supports three languages: its own Logs Insights query language, OpenSearch PPL and OpenSearch SQL. A typical query finds the slowest requests:
fields @timestamp, @duration | sort @duration desc | limit 10
Insights also discovers fields automatically in JSON logs and AWS service logs, groups similar lines into patterns, and can compare a time range with an earlier one. Queries are billed by the amount of data scanned, so narrow the time range and the log groups first.
Turning lines into metrics and alarms
A metric filter watches incoming events for a pattern, such as ERROR or a status code of 500, and turns matches into a CloudWatch metric. You can then put an alarm on that metric. Subscription filters stream matching events to Lambda, Kinesis or Firehose for processing elsewhere.
A common mistake is logging unstructured text. Write logs as JSON with consistent field names (requestId, userId, durationMs), and every query and filter becomes simpler.
Where AI fits
You don't need to know the query syntax to start. In the Logs Insights editor, choose Generate query and type a question in plain English, such as "find the 10 slowest requests" or "count errors per hour". CloudWatch generates the query, in Logs Insights QL, OpenSearch PPL or SQL, and adds a line-by-line explanation of how it works. You can refine it with a follow-up prompt. In some Regions the prompts are processed in US Regions, and AWS documents an opt-out policy for using your prompts to improve the service; check both if you have data residency rules.
Quick recap
- Log groups hold the settings; streams hold events from one source.
- Default retention is never expire: set it, or pay forever.
- Logs Insights searches many groups at once; metric filters feed alarms.
- Generate query turns plain English into a query with an explanation.