Skip to main content
This lesson shows how to configure advanced Amazon CloudWatch alarms and notifications for an EC2 instance. You’ll learn to:
  • Create an anomaly-detection alarm for CPU utilization
  • Create static-threshold alarms for NetworkIn and NetworkOut
  • Combine alarms into a composite alarm (AND / OR logic)
  • Configure SNS notifications and confirm subscriptions
  • Correctly delete composite and child alarms
  • Remove lingering anomaly-detection models if they persist
Prerequisite: an EC2 instance in the running state with status checks passed. You will apply alarms to that instance.

Prerequisites

1) Create an anomaly-detection alarm for CPUUtilization

Navigate to CloudWatch → Metrics → All metrics → EC2 → Per-Instance Metrics. Copy your EC2 Instance ID from the EC2 console and paste it into the metrics search field to filter to your instance. Select the CPUUtilization metric and open Graphed metrics, then click the bell icon → Create alarm to start the Create alarm wizard.
  • Data source: CloudWatch metrics
  • Type: Single metric
  • Metric: CPUUtilization for your InstanceId
A screenshot of the AWS CloudWatch "Create alarm" page showing an EC2 metric (CPUUtilization) for a specific instance with statistic and period settings. The right side displays threshold type and condition options (Static, Anomaly detection, Greater/Equal, etc.).
In the wizard you’ll see a metric preview and the Conditions section. Choose the threshold type “Anomaly detection” so CloudWatch builds a prediction band from historical behavior. The alarm evaluates when datapoints fall outside that predicted band.
A screenshot of the AWS CloudWatch "Create alarm" page showing a highlighted "Prediction band preview" warning about anomaly detection. The lower part shows the Conditions section with threshold type options (Static and Anomaly detection).
Anomaly detection adapts to normal workload patterns, unlike a static threshold that uses a fixed value. Open Additional configuration and set Data points to alarm to “3 out of 5”. This makes the alarm transition to ALARM only when 3 of 5 evaluation periods breach the predicted band — reducing false positives from single spikes.
A screenshot of the AWS CloudWatch "Create alarm" page showing a line graph of CPUUtilization with a shaded expected band and a red-dot spike in usage around 06:30. The browser tab bar and AWS account header are visible at the top.
For Actions, create or select an SNS topic to receive notifications when the alarm goes into ALARM state. If creating a new topic, add your email as a subscription endpoint — you’ll receive a confirmation email and must confirm the subscription to start receiving alarm notifications.
SNS reminder: subscriptions are pending confirmation until the recipient clicks the confirmation link in the email. CloudWatch will not send alarm notifications to that endpoint until the subscription is confirmed.
After creating the alarm, verify the subscription status on the SNS Subscriptions page — it will show as “Pending confirmation” until you confirm via email.
A screenshot of the Amazon Web Services SNS "Subscriptions" console. It shows one EMAIL subscription with status "Pending confirmation" and UI buttons for Edit, Delete, Request/Confirm, and Create subscription.
Confirm the subscription in your email client; after confirmation the subscription status will update and the alarm notifications will be delivered.
A screenshot of the AWS CloudWatch "Create alarm" page. It shows a form to create an SNS topic named "Default_CloudWatch_Alarms_Topic" with the email developercloud29@gmail.com and buttons for "Create topic" and "Add notification."
Once created, you have an adaptive anomaly-detection alarm on CPUUtilization that notifies the chosen SNS topic when 3 out of 5 datapoints fall outside the prediction band.

2) Create a NetworkIn static-threshold alarm

Return to Metrics → All metrics → EC2 → Per-Instance Metrics and select NetworkIn for your instance. Add it to Graphed metrics and click Create alarm. Choose a static threshold type and set a value appropriate for your workload (the demo used ~1.7 million bytes as an example). Configure Statistic and Period (e.g., Average over 5 minutes) to match your monitoring needs.
A screenshot of the AWS CloudWatch "Create alarm" page showing metric configuration for an EC2 instance (Namespace AWS/EC2, Metric name "NetworkIn", InstanceId) on the left and alarm Conditions (Static threshold selected) on the right. The preview/graph and other alarm options are visible below.
Attach an SNS topic (you can reuse the topic created earlier) and create the alarm. If network traffic exceeds your threshold, you’ll receive an SNS notification.
A screenshot of the AWS CloudWatch "Create alarm" page showing SNS notification options, with "Select an existing SNS topic" chosen and "Default_CloudWatch_Alarms_Topic" selected. An email endpoint (developercloud29@gmail.com) is also visible.
Name the alarm (for example: NetworkInAlarm) and finish the wizard.
A screenshot of the AWS CloudWatch "Create alarm" page showing the "Add alarm details" step. The Alarm name field is partially filled (starts with "NetworkInAla...") and the step list (Specify metric, Configure actions, Add alarm details) is visible on the left.

3) Create a NetworkOut static-threshold alarm

Follow the same process for NetworkOut: add it to Graphed metrics, choose a static threshold (demo used > 20,000 bytes as an example), select Statistic and Period, attach an SNS topic, and name the alarm NetworkOutAlarm.
A screenshot of the AWS CloudWatch "Create alarm" page showing a Metric configuration for an EC2 instance (Metric name: NetworkOut, InstanceId shown) with Statistic set to Average and Period set to 5 minutes.
Reuse the same SNS topic if desired.
A screenshot of the AWS CloudWatch "Create alarm" console showing SNS notification settings. The "Select an existing SNS topic" option is chosen with a topic selected and an email endpoint listed below.
When the alarms trigger, you’ll receive an email similar to the example below.
A screenshot of a Gmail message showing an AWS Notifications email about a CloudWatch alarm titled "ALARM: 'NetworkInAlarm' in US East (N. Virginia)". The message body details the alarm state change and includes a link to the AWS console.
Tip: If you receive frequent false positives, edit the alarm and adjust the threshold, statistic, or evaluation periods.

4) Create a Composite Alarm

Composite alarms evaluate the states of other alarms rather than metrics, letting you express higher-level logic such as “only alert if both NetworkIn and NetworkOut are anomalous”. From the Alarms console, select the child alarms to combine (e.g., NetworkInAlarm and NetworkOutAlarm) and choose Create composite alarm. Compose the expression using ALARM("AlarmName"):
  • AND logic (both must be ALARM):
  • OR logic (either one triggers):
A screenshot of the AWS CloudWatch "Create alarm" page on the Configure actions step, showing the Notification settings with the "In alarm" trigger selected and SNS topic options. The left sidebar shows the multi-step alarm creation workflow.
Select the SNS topic to notify for the composite alarm and create it. Composite alarms appear as parent alarms that reference the child alarms and do not show metric graphs; they show evaluated state based on child alarms.
A screenshot of the AWS CloudWatch Alarms console showing a green success banner reading "Successfully created alarm CompositeAlarm1." The alarms list below shows several alarms (e.g., CompositeAlarm1, NetworkInAlarm) with OK status.
The composite alarm details page shows its current state and lists referenced alarms.
A screenshot of the AWS CloudWatch console showing the details page for a CompositeAlarm1 alarm. The alarm state is shown as OK with actions enabled, and the left navigation menu and top browser tabs/region (US East) are visible.

5) Deleting alarms — ordering matters

When using composite alarms, always delete composite alarms before deleting any child alarms referenced by them. Attempting to delete a child alarm that a composite alarm references will fail. Example composite alarm ARN:
Delete process:
  • Delete the composite alarm first (Actions → Delete).
  • After the composite alarm is removed, delete each child alarm (e.g., NetworkInAlarm, NetworkOutAlarm).
  • Finally, delete any remaining alarms such as the anomaly-detection alarm if no longer needed.
Important: delete composite alarms before their child alarms. Deleting in the wrong order will fail and may leave alarms in a referenced state.

6) Removing lingering anomaly-detection models

Occasionally an anomaly-detection band may remain visible in the metric graph after you delete the alarm. Remove the anomaly model explicitly:
  • Go to Metrics → Graphed metrics for the affected metric (e.g., CPUUtilization).
  • Choose the metric and use the Delete model option to remove the anomaly detection model.
  • Confirm deletion in the dialog, then refresh the console to clear the anomaly band.
Screenshot of the AWS CloudWatch Metrics dashboard showing a "Delete model" confirmation dialog about removing an anomaly detection model for the metric "CPUUtilization." The modal warns about alarm recreation and offers Cancel or Delete options.
After deletion, clear the graph and refresh CloudWatch to ensure the anomaly band is removed.

Best practices

  • Use anomaly detection for adaptive metrics (CPU, latency) where baselining behavior yields better signal/noise.
  • Use static thresholds for simple signals (NetworkIn/NetworkOut) when a fixed cutoff is appropriate.
  • Use composite alarms to reduce noise and surface only actionable conditions (AND/OR logic).
  • Confirm SNS subscriptions promptly to ensure alerts are delivered.
  • Tune evaluation periods and datapoints (e.g., “3 out of 5”) to balance sensitivity and false positives.
  • Always delete composite alarms before deleting child alarms.

Summary

  • Anomaly detection: adaptive, ideal for CPU/latency patterns.
  • Static thresholds: predictable, ideal for network volume cutoffs.
  • Composite alarms: combine child alarm states into a single, actionable alert.
  • SNS: confirm subscriptions to receive notifications.
  • Deletion order: composite first, then child alarms.
  • Clean up anomaly models if they persist after alarm deletion.
This completes the lesson on configuring advanced CloudWatch alarms and notifications.

Watch Video

Practice Lab