17.5 SNS: email when the alarm changes
An alarm that only changes a word on a web page does not wake you. Amazon SNS (Simple Notification Service) delivers a message to whoever subscribed. The alarm does not know your inbox. It publishes to a topic. The topic delivers to each confirmed subscription.
A topic is the channel. Name it, and several alarms can share it. A subscription is one receiver. This lab uses email. The topic can have more than one subscription later. An unconfirmed address is not a receiver yet.
Worked example: the confirm email, then the alarm email
Use an inbox you open yourself. In the write-up, call it student@example.com. Type your real address in the console.
- SNS, Topics, Create topic. Type Standard. Name
scale-lab-alerts. A FIFO topic is for ordered application messages. An alarm notification does not need it. Create. - Create subscription. Topic
scale-lab-alerts. Protocol Email. Endpoint student@example.com. Create. - The console shows Pending confirmation. Open the inbox. Amazon SNS sent a confirmation message. The subject contains the topic name. Use Confirm subscription in that message. A browser page says the subscription is confirmed.
- Back in the SNS console, refresh. The status must say Confirmed. Pending is not "almost". Pending means publishes are dropped for that address.
Until step 4, you can do everything else in this chapter "correctly" and still get no mail. The alarm can sit in ALARM. The topic can exist. student@example.com receives nothing. Check spam before you blame CloudWatch.
Did the email arrive? Until you click the confirm link, SNS will not send anything.
Email आली का? Confirm link वर click केल्याशिवाय SNS काही पाठवणार नाही.
Email आई क्या? Confirm link पर click किए बिना SNS कुछ नहीं भेजेगा.
Tell the alarm to publish. Edit cpu-high-lab. Add a notification: state In alarm, topic scale-lab-alerts. Add the same topic again for state OK. Save. Button names may vary.
Two emails, two moments:
| When | Alarm state | What student@example.com receives |
|---|---|---|
| After the second period over 70 (82 then 91 in the worked table) | ALARM | A message that names cpu-high-lab, the new state ALARM, and the reason: the threshold was crossed |
| After the CPU has fallen and the periods are no longer over 70 | OK | A message that the same alarm returned to OK |
The OK email does not remove an EC2 instance. It is only the notification. Scale-in is a scaling policy, in the next section.
SNS still does not launch instances. Do not start yes yet.
The chain, in the order it runs
Say it in this order. Interviews go wrong when the email is described as the thing that launches the server.
- Metric. CPUUtilization average for a 5-minute period is a number. In the worked case the numbers are 82, then 91.
- Alarm. Both periods are greater than 70, so
cpu-high-labbecomes ALARM. - SNS email. The topic
scale-lab-alertssends that fact to every Confirmed subscription, including student@example.com. It does not send it to a Pending one. - Scaling policy. The policy that watches this alarm (section 17.6) adds 1 to desired capacity. The email does not do that. The policy does.
- Desired capacity. The Auto Scaling group moves from 1 to 2 and launches the extra instance, and will not go past the maximum of 3.
Steps 3 and 4 are both actions of the same alarm. They are not two different thresholds.
Ravindra Bagale's Tip
Many students say "the alarm went to ALARM, but the email never came." Look: if the subscription is still Pending confirmation, SNS does not send the email at all. Check the inbox and spam, click Confirm subscription, and continue only after the status is Confirmed. Do not forget.
Ravindra Bagale's Tip – मराठी
बरेच students म्हणतात "alarm ALARM झाला, पण email नाही आली." बघा — subscription Pending confirmation असेल तर SNS email पाठवतच नाही. Inbox आणि spam बघा, Confirm subscription दाबा, status Confirmed झाल्यावर पुढे जा. विसरू नका.
Ravindra Bagale's Tip – हिंदी
बहुत students कहते हैं "alarm ALARM हो गया, पर email नहीं आई." देखो — subscription Pending confirmation हो तो SNS email भेजता ही नहीं. Inbox और spam देखो, Confirm subscription दबाओ, status Confirmed होने पर आगे बढ़ो. मत भूलना.
Lab
Chala, one click per line. Use your real inbox where the page says student@example.com.
- Open SNS, then Topics.
- Choose Create topic.
- Choose type Standard.
- Name it
scale-lab-alerts. - Create the topic.
- Choose Create subscription.
- Set protocol to Email.
- Type your email address.
- Create the subscription.
- You should see status Pending confirmation.
- Open the email from Amazon SNS.
- Click Confirm subscription.
- Refresh the subscription in the console.
- You should see status Confirmed.
- Open CloudWatch alarm
cpu-high-lab. - Edit the notifications.
- Add topic
scale-lab-alertsfor state In alarm. - Add the same topic for state OK.
- Save.
- Do not run
yesyet.