-: Now let's discuss CloudWatch Alarms.
So alarms, as we know,
they're used to trigger notifications from any metric.
And you can define complex alarms
and on various options such as sampling,
or doing percentage, or max, min and so on.
Alarm has three states,
OK means that it's not triggered,
insufficient data means that there's not enough data
for the alarm to determine a state,
and alarm, which is that your threshold has been breached
and therefore a notification will be sent.
The period is how long you want the alarm
to evaluate for on the metric
and so it could be very, very short or very, very long,
and it can apply also to high resolution custom metrics.
For example, 10 seconds, 30 seconds,
or a multiple of 60 seconds.
Now, alarms have three main targets,
the first one is actions on EC2 Instances,
such as stopping it, terminating it, rebooting it,
or recovering an instance.
The second one is to trigger an auto-scaling action,
for example, a scale out or a scale in.
And the last one is to send a notification
to the SNS service, for example,
and from the SNS service we can hook it
to a lambda function and have the lambda function
do pretty much anything we want based
on an alarm being breached.
So, let's talk about EC2 Instance Recovery.
We've already seen it,
but there's a status check to check the EC2 VM
and the system status check
to check the underlying hardware.
And you can define a CloudWatch Alarm
on both of these checks.
Okay, so you will monitor a specific EC2 Instance
and in case the alarm is being breached,
then you can start an EC2 Instance Recovery
to make sure, for example,
that you move your EC2 Instance
from one host to another.
When you do a recovery,
you get the same private, public,
and elastic IP, the same metadata,
and the same placement group for your instance.
And you can also send an alarm and alerts to your SNS Topic
to get alerted that the EC2 Instance was being recovered.
Now the CloudWatch Alarm has some good stuff.
So, you know, that first of all
is that as we've seen,
we can create an alarm on top
of a CloudWatch Logs Metric Filter.
So remember,
the CloudWatch Logs are having a metric filter,
which is hooked to a CloudWatch Alarm
and then when we receive too many instances
of a specific word, for example, the word error,
then do an alert and send a message into Amazon SNS.
And so if you want it to test alarm notifications,
you can use a CLI Call called set alarm state.
And this is helpful when you want to trigger an alarm,
even though it didn't reach a specific specific threshold,
because you wanted to see whether or not the alarm being
triggered results in the correct action
for your infrastructure.
So that's it for alarms.
I hope you liked it,
and I will see you in the next lecture for some practice.