Alarm actions (SNS, Auto Scaling) in AWS - Time & Space Complexity
When alarms trigger actions like sending messages or scaling servers, the time it takes depends on how many alarms and actions there are.
We want to know how the number of alarms affects the total work done by the system.
Analyze the time complexity of the following operation sequence.
// Create CloudWatch alarm
aws cloudwatch put-metric-alarm --alarm-name MyAlarm --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 70 --comparison-operator GreaterThanThreshold --evaluation-periods 2 --alarm-actions arn:aws:sns:region:account-id:MyTopic arn:aws:autoscaling:region:account-id:scalingPolicy:policy-id:autoScalingGroupName/groupName:policyName/policy
// Alarm triggers SNS notification and Auto Scaling policy
This sequence sets an alarm that sends a notification and triggers scaling when CPU usage is high.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Sending alarm actions (SNS notifications and Auto Scaling triggers)
- How many times: Once per alarm evaluation period when the alarm state changes
Each alarm can trigger multiple actions. As the number of alarms grows, the total actions triggered grow proportionally.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 alarms | About 10 sets of actions triggered |
| 100 alarms | About 100 sets of actions triggered |
| 1000 alarms | About 1000 sets of actions triggered |
Pattern observation: The total work grows directly with the number of alarms.
Time Complexity: O(n)
This means the total actions triggered grow in direct proportion to the number of alarms.
[X] Wrong: "Adding more alarms won't increase the number of actions triggered because they run independently."
[OK] Correct: Each alarm triggers its own actions, so more alarms mean more total actions and API calls.
Understanding how alarm actions scale helps you design systems that handle many alerts smoothly and keep cloud costs predictable.
"What if we combined multiple alarms into one composite alarm? How would the time complexity change?"
Practice
Solution
Step 1: Understand SNS topic role
SNS topics are used to send messages or notifications to subscribers.Step 2: Connect alarm to SNS for notifications
When an alarm changes state, it can trigger SNS to notify users or systems.Final Answer:
To send notifications when the alarm state changes -> Option BQuick Check:
Alarm + SNS = Notifications [OK]
- Confusing SNS with Auto Scaling actions
- Thinking SNS stores logs
- Assuming SNS creates backups
Solution
Step 1: Identify correct ARN format for Auto Scaling policy
Auto Scaling policy ARNs include 'autoscaling' and specify scalingPolicy and group name.Step 2: Match with given options
{ "AlarmActions": ["arn:aws:autoscaling:region:account-id:scalingPolicy:policy-id:autoScalingGroupName/group-name:policyName/policy-name"] } matches the correct ARN format for Auto Scaling alarm action.Final Answer:
Correct Auto Scaling policy ARN format -> Option AQuick Check:
Auto Scaling action uses autoscaling ARN [OK]
- Using SNS ARN instead of Auto Scaling ARN
- Confusing Lambda or S3 ARNs as alarm actions
- Incorrect ARN structure
{
"AlarmName": "HighCPU",
"MetricName": "CPUUtilization",
"Namespace": "AWS/EC2",
"Threshold": 80,
"ComparisonOperator": "GreaterThanThreshold",
"EvaluationPeriods": 2,
"AlarmActions": ["arn:aws:sns:us-east-1:123456789012:NotifyMe"]
}What happens when the CPU utilization exceeds 80% for 2 evaluation periods?
Solution
Step 1: Analyze AlarmActions ARN
The AlarmActions list contains an SNS topic ARN, meaning notifications are sent on alarm.Step 2: Understand alarm trigger
When CPUUtilization > 80% for 2 periods, alarm state changes and triggers SNS notification.Final Answer:
An SNS notification is sent to subscribers of the NotifyMe topic -> Option AQuick Check:
Alarm with SNS ARN sends notifications [OK]
- Assuming Auto Scaling happens without scaling policy
- Thinking alarm resets silently
- Confusing SNS with Lambda triggers
Solution
Step 1: Check AlarmActions configuration
If the Auto Scaling policy ARN is missing or incorrect, the alarm cannot trigger scaling.Step 2: Rule out other options
SNS subscription missing affects notifications, not scaling. Threshold too low triggers alarm but no scaling if policy missing. Stopped instances do not scale but alarm triggers still need correct action.Final Answer:
The alarm's AlarmActions does not include the correct Auto Scaling policy ARN -> Option DQuick Check:
Correct Auto Scaling ARN needed in AlarmActions [OK]
- Confusing SNS subscription with scaling trigger
- Ignoring ARN correctness
- Assuming stopped instances auto scale
Solution
Step 1: Understand alarm actions for scaling and notifications
To scale automatically, the alarm must trigger the Auto Scaling policy. To notify, it must trigger the SNS topic.Step 2: Combine both actions in one alarm
Adding both ARNs in AlarmActions ensures the alarm triggers scaling and sends notifications simultaneously.Final Answer:
Add both the Auto Scaling policy ARN and the SNS topic ARN to the alarm's AlarmActions -> Option CQuick Check:
Multiple AlarmActions allow scaling + notifications [OK]
- Thinking one ARN can do both scaling and notifications
- Creating multiple alarms unnecessarily
- Missing one of the required ARNs
Ready to prove it?
Pass the test and this pattern moves unknown
