Home › Modules › Module 09

📈 Module 09 · CloudWatch & SNS

Amazon CloudWatch, Dashboards, Metrics, Thresholds, Alarms and Actions, Statistics for EC2, and Amazon SNS Topics and Subscriptions

6 hours11 practice questions 5 sections

🎯 By the end of this module you should be able to…

  • Explain what CloudWatch collects and the difference between metrics, logs, alarms and dashboards.
  • Name the EC2 metrics available by default and explain why memory and disk are not among them.
  • Set a sensible threshold using period, evaluation periods and datapoints to alarm.
  • Describe the three CloudWatch alarm states and what triggers a transition.
  • Configure alarm actions: notify, auto scale, or recover the instance.
  • Explain the SNS publish/subscribe model and the role of topics and subscriptions.
  • Wire a CloudWatch alarm to an SNS topic so a human is actually told.

What Amazon CloudWatch is

CloudWatch is the monitoring and observability service for AWS. It answers two different questions: is this healthy right now? and what happened at 03:40 last night?

ComponentWhat it holdsYou use it to
MetricsTime-ordered numbers — CPU %, request count, queue depthSee trends and drive alarms
LogsText lines from applications, the OS and AWS servicesFind out what actually happened
AlarmsA rule watching one metric or a metric expressionTrigger a notification or an action
DashboardsCharts and numbers arranged on one pageGive a team a single shared view
Events / EventBridgeA stream of state changes in your accountReact automatically to things happening
Logs InsightsA query language over your logsAsk "how many 500s, grouped by path?"
Namespace, metric, dimension — three words worth getting right

A namespace groups metrics by service, for example AWS/EC2. A metric is the thing measured, for example CPUUtilization. A dimension is a name/value pair that identifies which resource, for example InstanceId=i-0abc123. The three together identify exactly one line on a chart.

EC2 metrics you get for free — and the two you do not

MetricWhat it tells you
CPUUtilizationPercentage of allocated compute in use
NetworkIn / NetworkOutBytes in and out of all network interfaces
NetworkPacketsIn / OutPacket counts
DiskReadOps / DiskWriteOpsI/O operations on instance store volumes
DiskReadBytes / DiskWriteBytesBytes read and written to instance store
StatusCheckFailed_SystemA problem on the AWS side — host, network, power
StatusCheckFailed_InstanceA problem inside your instance — OS, filesystem, network config
Memory and disk space are not in that list

CloudWatch sees the instance from outside the hypervisor, so it cannot see what the guest operating system is doing with RAM or how full a filesystem is. To get those you install the CloudWatch agent, which publishes them as custom metrics. This is the most common gap in a new monitoring setup — and a favourite exam question.

Basic monitoringDetailed monitoring
Interval5 minutes1 minute
CostFreeCharged per instance per month
Use forDevelopment, non-critical workloadsProduction, and anything driving auto scaling

Dashboards

A dashboard is a saved arrangement of widgets. It is global — one dashboard can show metrics from several Regions and several accounts at once, which is exactly what an operations team needs.

What makes a dashboard worth having

  • 👁️It answers one question "Is the shop working?" Not "here is every metric we collect."
  • ⬆️Most important at the top left People read a screen the way they read a page.
  • 📉Four golden signals Latency, traffic, errors, saturation. If you only have room for four charts, use those.
  • 📏A threshold line on every chart A number is meaningless without the line that says what "too high" is.
  • ⏱️A sensible default time range Three hours for an operations screen; a week for a capacity review.

Widget types

📈LineA metric over time — the default
📊Stacked areaComposition, such as requests per instance
🔢NumberOne large current value
🚦Alarm statusRed/green at a glance
📋Logs tableLive Logs Insights query results
📝TextRunbook links and context for whoever is on call
Automatic dashboards already exist

Before you build anything, open the automatic dashboards CloudWatch creates per service. They are free, maintained by AWS, and often good enough. Build a custom dashboard only when you need metrics from several services on one screen.

Metrics, thresholds and statistics

A threshold that is too tight pages you at 3 a.m. for nothing. A threshold that is too loose never fires. Four settings decide the behaviour.

SettingWhat it controlsSensible starting point
StatisticHow the raw datapoints are aggregatedAverage for CPU; Sum for counts; p90/p99 for latency
PeriodThe length of each aggregation window5 minutes (1 minute if detailed monitoring is on)
Evaluation periodsHow many recent periods are examined3
Datapoints to alarmHow many of those must breach2 of 3 — rides out a single spike
Use "M out of N" to stop false alarms

"CPU > 80% for 2 out of the last 3 five-minute periods" survives one transient spike but still fires within about ten minutes of a real problem. A plain "1 out of 1" alarm on a noisy metric is how teams learn to ignore alerts.

Which statistic to use

StatisticGood forCareful of
AverageUtilisation like CPU or memoryHides a single struggling instance in a fleet
SumCounts — requests, errors, messagesMeaningless for a percentage
MaximumCatching any single bad datapointVery noisy on its own
MinimumSpotting something that stopped reportingRarely what you want for load
p90 / p99Latency — the experience of your slowest usersNeeds enough traffic to be meaningful
Average latency lies

If 99 requests take 50 ms and one takes 10 seconds, the average is about 150 ms and everything looks fine — while one customer waited ten seconds. Alarm on p99, chart the average.

Alarms and actions

StateMeaning
OKThe metric is within the threshold
ALARMThe threshold has been breached for the configured number of datapoints
INSUFFICIENT_DATANot enough data — the alarm is new, the resource is stopped, or the metric stopped reporting

An action fires on the transition into a state, not continuously while in it. That is why you should configure an action for the return to OK as well — otherwise nobody is told that it recovered.

What an alarm can do

📢 Notify

Publish to an SNS topic, which then fans out to email, SMS, a chat webhook, a Lambda function or a ticketing system.

📈 Auto Scaling action

Add or remove instances from an Auto Scaling group. This is how a workload follows demand automatically.

🔧 EC2 action

Stop, terminate, reboot or recover an instance. Recover is the classic response to StatusCheckFailed_System.

🧩 Systems Manager action

Create an OpsItem or run an Automation document — the bridge to real self-healing.

Composite alarms

A composite alarm combines other alarms with AND, OR and NOT. Instead of five separate pages when one database fails, you raise one alarm that says "the checkout service is unhealthy". This is the main tool against alert fatigue.

A worked configuration

Goal Tell the on-call engineer when the web tier is under strain. Metric AWS/EC2 CPUUtilization Dimension AutoScalingGroupName = web-asg Statistic Average Period 5 minutes Condition Greater than 75 Evaluation 3 periods Datapoints 2 out of 3 Action (ALARM) Publish to SNS topic ops-alerts Action (OK) Publish to SNS topic ops-alerts Missing data Treat as missing (do not alarm)
Anomaly detection

Instead of a fixed number, CloudWatch can learn a metric's normal pattern — including its daily and weekly cycles — and alarm when it leaves the expected band. Use it for metrics whose "normal" changes through the day, where a single fixed threshold would be wrong at some hour.

Amazon SNS

Simple Notification Service is a fully managed publish/subscribe messaging service. A publisher sends one message to a topic; SNS delivers a copy to every subscription on that topic. The publisher never knows or cares who is listening.

CloudWatch alarm publisher SNS topic ops-alerts ✉ Email — the ops team 📱 SMS — on-call phone λ Lambda — auto remediation 📥 SQS — ticket queue
One publish, four deliveries. Add a fifth subscriber and nothing upstream changes.

Topics and subscriptions

StepWhat you specifyNotes
1. Create a topicType (Standard or FIFO), name, display nameStandard for notifications; FIFO when strict ordering and exactly-once matter
2. Set access policyWho may publish, who may subscribeLeast privilege applies here too
3. Create a subscriptionProtocol and endpointEmail, SMS, HTTPS, Lambda, SQS, mobile push, or an email-JSON feed
4. Confirm the subscriptionClick the link in the confirmation messageEmail and HTTPS subscriptions deliver nothing until confirmed.
5. Publish and testSend a test message from the console or CLIAlways test before you rely on it
"Pending confirmation" is the number one SNS problem

A subscription sits in PendingConfirmation until the recipient clicks the link in the email AWS sends. Until then the alarm fires, SNS publishes, and nobody hears anything. If an alert "did not arrive", check the subscription status before you check anything else.

Useful features

🧲 Message filtering

A subscription filter policy means one topic can serve everyone: the database team subscribes only to messages where service = "rds".

📪 Fan-out to SQS

SNS to several SQS queues is the classic decoupling pattern: each consumer processes at its own pace, and a slow consumer cannot block the others.

♻️ Dead-letter queues

Messages that cannot be delivered after retries go to an SQS DLQ instead of disappearing.

🔐 Encryption

Server-side encryption with KMS, and HTTPS in transit. Worth turning on for anything carrying operational detail.

SNS or SQS?

SNS pushes one message to many subscribers immediately — use it for notifications and fan-out. SQS holds messages in a queue until a consumer pulls them — use it for decoupling and buffering work. They are complementary, and the fan-out pattern uses both together.

Key takeaways

  • CloudWatch collects metrics, logs, alarms, dashboards and events.
  • EC2 gives CPU, network, disk I/O and status checks for free — memory and disk space need the CloudWatch agent.
  • Basic monitoring is 5-minute and free; detailed is 1-minute and charged.
  • Use M-out-of-N evaluation to ride out spikes without missing real problems.
  • Alarm on p99 latency, not the average.
  • Alarm actions fire on the transition into a state — configure the OK action too.
  • SNS is publish/subscribe: one topic, many subscriptions, one publish delivered to all.
  • Email and HTTPS subscriptions deliver nothing until they are confirmed.

Quiz