Bird
Raised Fist0
AWScloud~30 mins

CloudWatch alarms in AWS - Mini Project: Build & Apply

Choose your learning style10 modes available
Create a CloudWatch Alarm for CPU Utilization
📖 Scenario: You are managing a cloud server and want to monitor its CPU usage. If the CPU usage goes above a certain limit, you want to get notified automatically.
🎯 Goal: Build a CloudWatch alarm that watches the CPU utilization of an EC2 instance and triggers when the usage is above 70% for 5 minutes.
📋 What You'll Learn
Create a variable with the EC2 instance ID
Set a threshold value for CPU utilization
Define a CloudWatch alarm using the instance ID and threshold
Configure the alarm to trigger after 5 minutes of high CPU usage
💡 Why This Matters
🌍 Real World
CloudWatch alarms are used by cloud engineers to monitor server health and get alerts before problems affect users.
💼 Career
Knowing how to configure CloudWatch alarms is essential for roles like Cloud Engineer, DevOps Engineer, and Site Reliability Engineer.
Progress0 / 4 steps
1
Set the EC2 instance ID
Create a variable called instance_id and set it to the string "i-0abcd1234efgh5678" which represents your EC2 instance ID.
AWS
Hint

The EC2 instance ID is a string. Use quotes around it.

2
Set the CPU utilization threshold
Create a variable called cpu_threshold and set it to the number 70 which will be the CPU usage percentage limit for the alarm.
AWS
Hint

Threshold is a number without quotes.

3
Define the CloudWatch alarm configuration
Create a dictionary called cloudwatch_alarm with these exact keys and values: AlarmName set to "HighCPUAlarm", MetricName set to "CPUUtilization", Namespace set to "AWS/EC2", Statistic set to "Average", Period set to 60, EvaluationPeriods set to 5, Threshold set to the variable cpu_threshold, ComparisonOperator set to "GreaterThanThreshold", and Dimensions set to a list with one dictionary containing Name as "InstanceId" and Value as the variable instance_id.
AWS
Hint

Use a dictionary with the exact keys and values. Use the variables for threshold and instance ID.

4
Add the alarm action configuration
Add a key called AlarmActions to the cloudwatch_alarm dictionary and set its value to a list containing the string "arn:aws:sns:us-east-1:123456789012:NotifyMe" which represents the SNS topic ARN to notify when the alarm triggers.
AWS
Hint

AlarmActions is a list with one string ARN.

Practice

(1/5)
1. What is the primary purpose of an AWS CloudWatch alarm?
easy
A. To store large amounts of log data
B. To monitor a specific metric and notify when it crosses a threshold
C. To create virtual servers in the cloud
D. To manage user permissions and roles

Solution

  1. Step 1: Understand CloudWatch alarm function

    CloudWatch alarms watch metrics like CPU usage or disk space and alert you when values cross set limits.
  2. Step 2: Identify the correct purpose

    Only To monitor a specific metric and notify when it crosses a threshold describes monitoring a metric and notifying on threshold crossing, which is the alarm's job.
  3. Final Answer:

    To monitor a specific metric and notify when it crosses a threshold -> Option B
  4. Quick Check:

    Alarm = Monitor + Notify [OK]
Hint: Alarms watch metrics and alert on changes [OK]
Common Mistakes:
  • Confusing alarms with log storage
  • Thinking alarms create servers
  • Mixing alarms with user management
2. Which of the following is the correct way to specify a CloudWatch alarm threshold for CPU utilization above 80%?
easy
A. "Threshold": "<=80"
B. "Threshold": 80, "ComparisonOperator": "LessThanThreshold"
C. "Threshold": 80, "ComparisonOperator": "LessThanOrEqualToThreshold"
D. "Threshold": 80, "ComparisonOperator": "GreaterThanThreshold"

Solution

  1. Step 1: Understand threshold syntax

    CloudWatch alarms use a numeric Threshold value and a separate ComparisonOperator like GreaterThanThreshold, LessThanThreshold.
  2. Step 2: Choose operator for above 80%

    To alert when CPU is above 80%, use "Threshold": 80, "ComparisonOperator": "GreaterThanThreshold".
  3. Final Answer:

    "Threshold": 80, "ComparisonOperator": "GreaterThanThreshold" -> Option D
  4. Quick Check:

    Above 80% = GreaterThanThreshold(80) [OK]
Hint: Use GreaterThanThreshold for above threshold [OK]
Common Mistakes:
  • Using < instead of > for above threshold
  • Using = which triggers only at exact value
  • Confusing <= with above threshold
3. Given this CloudWatch alarm configuration snippet:
{"MetricName": "CPUUtilization", "Namespace": "AWS/EC2", "Threshold": 70, "ComparisonOperator": "GreaterThanThreshold", "EvaluationPeriods": 3}

What happens if CPU utilization is 75% for 2 consecutive periods and then 65% for the third period?
medium
A. The alarm does not trigger because CPU was not above 70% for all 3 periods
B. The alarm triggers only if CPU is above 70% for 4 periods
C. The alarm triggers immediately when CPU hits 75% the first time
D. The alarm triggers because CPU was above 70% twice

Solution

  1. Step 1: Understand EvaluationPeriods meaning

    The alarm triggers only if the metric breaches the threshold for the specified number of consecutive periods (3 here).
  2. Step 2: Analyze given CPU values

    CPU was above 70% for 2 periods, then dropped below on the 3rd, so the alarm does not trigger.
  3. Final Answer:

    The alarm does not trigger because CPU was not above 70% for all 3 periods -> Option A
  4. Quick Check:

    3 periods breach needed, only 2 met [OK]
Hint: Alarm needs all evaluation periods breached [OK]
Common Mistakes:
  • Thinking alarm triggers after any single breach
  • Ignoring EvaluationPeriods count
  • Assuming alarm triggers immediately
4. You created a CloudWatch alarm but it never enters ALARM state even when the metric crosses the threshold. What is a likely cause?
medium
A. The alarm's EvaluationPeriods is set higher than the number of metric data points
B. The alarm threshold is set too low
C. The alarm is configured to notify but not to monitor metrics
D. The SNS topic ARN configured in alarm actions is invalid

Solution

  1. Step 1: Check EvaluationPeriods vs data points

    If EvaluationPeriods is more than available metric data points, alarm cannot evaluate properly.
  2. Step 2: Confirm impact on alarm state

    Without enough data points, alarm never sees enough breaches to enter ALARM state.
  3. Final Answer:

    The alarm's EvaluationPeriods is set higher than the number of metric data points -> Option A
  4. Quick Check:

    EvaluationPeriods > data points = no alarm [OK]
Hint: Ensure enough data points for EvaluationPeriods [OK]
Common Mistakes:
  • Assuming threshold too low prevents alarm
  • Confusing notification with monitoring
  • Thinking invalid SNS prevents alarm state
5. You want to create a CloudWatch alarm that triggers an auto-scaling action when average CPU utilization exceeds 60% for 5 minutes, but only if this happens during business hours (9 AM to 5 PM). Which approach best achieves this?
hard
A. Create a CloudWatch alarm with threshold 60% and EvaluationPeriods 1, then use EventBridge to trigger scaling only during business hours
B. Set the alarm threshold to 60% and EvaluationPeriods to 5, and configure the alarm to be active only during business hours
C. Create a CloudWatch alarm with threshold 60% and EvaluationPeriods 5, then use a Lambda function triggered by the alarm to check time and trigger scaling
D. Set the alarm threshold to 60% and EvaluationPeriods 5, and configure auto-scaling to ignore alarms outside business hours

Solution

  1. Step 1: Understand alarm and time condition needs

    CloudWatch alarms alone cannot restrict triggering by time; external logic is needed.
  2. Step 2: Evaluate options for time-based control

    Using a Lambda triggered by the alarm to check current time and decide on scaling is flexible and precise.
  3. Step 3: Assess other options

    EventBridge can schedule events but not filter alarm triggers by time; auto-scaling ignores alarms is not a feature.
  4. Final Answer:

    Create a CloudWatch alarm with threshold 60% and EvaluationPeriods 5, then use a Lambda function triggered by the alarm to check time and trigger scaling -> Option C
  5. Quick Check:

    Alarm + Lambda time check = controlled scaling [OK]
Hint: Use Lambda to add time logic after alarm triggers [OK]
Common Mistakes:
  • Expecting alarm to handle time filtering alone
  • Assuming auto-scaling ignores alarms by time
  • Using EventBridge without alarm integration
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard