Sending an SNS Notification when Alarm state changes to OK - amazon-web-services

I have monitored the status of VPN tunnels in my account.I have created CloudWatch alarms and configured SNS notifications when they are down.
At the moment, that is working fine. Now, I have got another requirement saying I have to send alarm whenever the state changes to OK.
This is the image of the alarm configuration :
There, in the snapshot, it says :
Whenever this alarm : STATE is ALARM
I would change that to :
Whenever this alarm : STATE is OK
But, by doing that, will the Cloud Watch send me notifications every 5 minutes until the state is in OK?
I have this doubt because it is written STATE is OK instead of STATE changes to OK.
Please let me know.

An Amazon CloudWatch alarm only sends a notification on a change of state.
So, if your alarm is set to send a notification when State = OK: If the state is already OK, it will not send a notification. However, when the state changes to something else and the changes back to OK, it would send a notification.

Related

CloudWatch alarm doesn't trigger action if it changes state while having alarm actions disabled

I'm using enable_alarm_actions() / disable_alarm_actions() on CloudWatch alarm to implement mechanism for downtiming CloudWatch alarms.
If the alarm changed it state, while it's "downtimed" (ActionsEnabled property is set to false) it doesn't trigger corresponding action, as expected. But when you enable_alarm_actions() back the action on the alarm still not triggering. And you're running into situation, when you're not notified when the alarm went to ALARM state while being downtimed after downtime expires.
So, the question, is this expected and is there a way to manually trigger an action on the alarm?
If I understand correctly what you are describing, is that Cloudwatch wont trigger action when it is in alarm state and when you enable its action.
This is by design. Alarms invoke actions only when alarm change state occurs. Being in alarm state is not enough.
The docs write:
Alarms invoke actions for sustained state changes only. CloudWatch
alarms don't invoke actions simply because they are in a particular
state, the state must have changed and been maintained for a specified
number of periods.
So when your actions are enabled when Alarm is already in alarm state, nothing is going to happen. You have to wait for next alarm state changes.

CloudWatch alarm action only triggers SNS once

I have a CloudWatch alarm created for testing purposes. It checks the number of bytes read on a Kinesis Stream. If less than 1 bytes are received within 1 minute, it triggers alarm and send email via SNS. So, I get email after 1 min, but then after that I don’t get any further email. Is it right the email notification sent only once? In my test data is not flowing all the time. So, ideally, it should send email every minute. Correct?
Whether or not the action keeps firing depends on the type of action.
SNS actions only trigger once when the state changes to ALARM. Other actions such as EC2 auto scaling keep triggering as long as the alarm is in ALARM state.
If your alarm reverts to OK state and then back again to ALARM, SNS will get triggered again.
AWS docs
If CloudWatch alarm switched to ALARM state after specified period (1 minute), then in your case it means it received less than 1 byte. When switched, it will trigger configured actions (in your case it is email notification). As long as alarm remains in the ALARM state without switching it state back to OK, nothing will be triggered again.
if alarm returned back to OK state and then again after the specified period it switched to ALARM, configured action will be triggered again.
For more information, refer to documentation.

Want SNS alert repeatedly

I had setup an Alert for CPU utilization on EC2 instance. Created one SNS topic to send alerts on mail. It sends me an alert when CPU utilization goes to ALARM state but I want repeated alerts till ALARM state get resolved. Please help me... I'm newbie to AWS.
What you can do is setup a Lambda function with a CloudWatch event trigger so that it runs periodically, and inside it call the CloudWatch GetMetricStatistics API. Then, simply check if it is above or below your preferred threshold (or if you want, whether or not it's in Alarm state) and publish a message to SNS. There are a lot of SDK documentations on how to use these API's with your preferred language.
It is not possible to get repeated notifications after getting into the ALARM state. As the alarm is entering the ALARM state only once that means the notification via Amazon SNS will be sent only once.
Autoscaling policy will be triggered by the same alarm. But mail will be sent only once.

Usefulness of Publish the Value Zero for cloudwatch

According to this doc I should consider publishing value zero instead of no data because I "can set a CloudWatch alarm to notify you if your application fails to publish metrics every five minute".
But I can set a cloudwatch alarm to notify on INSUFFICIENT_DATA too. Is using 0 a more reliable way of doing this? Is using 0 over INSUFFICIENT_DATA recommended by amazon because its more reliable?
You can set an alarm via either method.
However, there is a difference between publishing a value of zero and an alarm state of INSUFFICIENT_DATA.
If your service is running, then publish a zero value instead of not publishing and having the alarm go into the INSUFFICIENT_DATA state. In the first case you know your service is running. In the second case you have no data. This may or not be valuable to you but at least your log files will not have missing time areas.

Sending SNS notification when an instance is stopped

At some point in a day, one of my instances gets stopped and I am trying to send an SNS notification at that time.
I can do it in multiple ways:
1.) Create an alarm on the metric StatusCheckFailed_Instance and when this reaches Insufficient_Data state, i configure it to send an SNS notification.
2.) I can write a lambda script (put_metric_alrm) to create it for me and send it when state changes to Insufficient_Data.
My problem while doing this is the notification is being sent once a day if my instance is stopped for days. Instead, I want a notification to be sent only when it gets stopped.
How can I do this? Please suggest.
Take a look at CloudWatch Events; you can create a new 'rule' such that an event will trigger on EC2 instance state-change notifications for a given instanceid where the state is 'stopped'. When the event is fired, you can then invoke an SNS topic to get notified of the change.
Here is an example configuration:
Service Name: EC2
Event Type: EC2 Instance State-change notification
Specific state(s): stopped
Specific instances: Your Instance ID
Targets: Your SNS Topic Name
The same example, as seen in the CloudWatch Events console:
Simply subscribe your SMS or email to the SNS topic, and you'll get notified when this instance enters the stopped state.
See also:
AWS API Documentation - PutRule
AWS CLI Documentation - aws events put-rule