# CloudWatch Metrics, Logs and Alarms

> Collect metrics and logs, query them with Logs Insights, build dashboards and alert on symptoms that matter to users. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/cloud-engineer/cloudwatch
Last updated: 2026-11-28

Collect metrics and logs, query them with Logs Insights, build dashboards and alert on symptoms that matter to users.

Intermediate · about 5 hours · difficulty 2/5

Learn first: [AWS Lambda Functions](https://www.internhack.in/roadmaps/tracks/cloud-engineer/lambda), [EC2 Instances, AMIs and Pricing Options](https://www.internhack.in/roadmaps/tracks/cloud-engineer/ec2-fundamentals)

**Amazon CloudWatch** is the default monitoring service on AWS. Azure Monitor and Google Cloud Monitoring/Logging are the equivalents.

### Metrics

- AWS services publish metrics automatically (EC2 CPU, ALB request count and 5xx errors, Lambda duration and errors, RDS connections).
- EC2 memory and disk need the **CloudWatch agent**.
- Publish **custom metrics** (orders placed, payment failures) or use the **Embedded Metric Format** in logs.
- Understand **statistics** (average, p95, p99) and **periods**. Averages hide slow requests; watch percentiles.

### Logs

- **Log groups** and **log streams** collect logs from Lambda, ECS, API Gateway and the agent.
- Set a **retention period**; the default is to keep logs forever and pay for them forever.
- **Logs Insights** queries logs with a simple query language: filter errors, count by status code, find slow requests.
- **Metric filters** turn log patterns into metrics you can alarm on.

### Alarms and dashboards

- **Alarms** watch a metric and notify SNS (email, Slack via Chatbot) or trigger actions like Auto Scaling.
- Alert on **symptoms users feel** (error rate, latency) rather than every CPU spike.
- **Composite alarms** reduce noise; **anomaly detection** learns normal patterns.
- **Dashboards** give one view of a service's health.

### Pitfalls

- Never-expiring log groups quietly growing your bill.
- Alert fatigue from dozens of noisy alarms.
- Logging secrets or personal data such as Aadhaar or phone numbers.

You are ready to move on when you can build a dashboard for your API, write a Logs Insights query that finds the slowest requests, and get an email when the error rate crosses a threshold.

## Key concepts

- **Built-in service metrics**
- **CloudWatch agent**
- **Custom metrics and EMF**
- **Percentiles vs averages**
- **Log groups and retention**
- **Logs Insights queries**
- **Alarms and SNS notifications**
- **Dashboards**
- **Composite and anomaly alarms**

## Mini project

For your serverless notes API, set 7-day log retention, build a dashboard (requests, errors, p95 latency), write two Logs Insights queries, and create an alarm that emails you via SNS when Lambda errors exceed 5 in 5 minutes. Trigger it deliberately. A few alarms and a dashboard fit the free tier; delete them when done.

## Check yourself

Why might average latency look fine while users complain the app is slow? Which statistic would you alarm on?

## Free resources

- [Amazon CloudWatch documentation](https://docs.aws.amazon.com/cloudwatch/) (AWS)
- [CloudWatch Logs Insights query syntax](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html) (AWS)
- [One Observability Workshop](https://catalog.workshops.aws/observability/) (AWS)

Previous: [Deployment Strategies and Safe Releases](https://www.internhack.in/roadmaps/tracks/cloud-engineer/deployment-strategies) · Next: [Distributed Tracing with X-Ray and OpenTelemetry](https://www.internhack.in/roadmaps/tracks/cloud-engineer/xray-tracing)

## More in Observability and Auditing

- [CloudWatch Metrics, Logs and Alarms](https://www.internhack.in/roadmaps/tracks/cloud-engineer/cloudwatch)
- [Distributed Tracing with X-Ray and OpenTelemetry](https://www.internhack.in/roadmaps/tracks/cloud-engineer/xray-tracing)
- [Auditing with CloudTrail and AWS Config](https://www.internhack.in/roadmaps/tracks/cloud-engineer/cloudtrail-config)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cloud Engineer (AWS) Roadmap](https://www.internhack.in/roadmaps/tracks/cloud-engineer)
