Instructor: Let's have a play with status checks.
So if we go into my first instance
and look at the status check tab.
As you can see, we can see there's two status checks
that are being run so there's a system status check
and an instance status check, okay?
And in case you are not happy with these checks
and you believe that there's an error,
you can click on report instance status
to help address detect issues.
So what we can do though because our thing's running,
we can still go ahead and create our CloudWatch alarm
that will have a reboot or recover action on our instance.
So I'll do action
and then I will click on create status check alarm.
So we create a new alarm
and then we have an alarm notification
so we can send it to the default CloudWatch alarms topic
if you want to have a notification,
but you could disable it as well if you wanted to.
And in the alarm action,
so what do you want to do when the alarm is triggered?
And we have two options that could be very helpful for us.
So recover or reboot.
So recover is going to be very helpful
when we want to recover from a physical host issue from AWS.
A reboot when it's a software issue.
So I will choose recover
and then we need to look at the alarm thresholds.
So we want to have the status check failed,
for example, either.
So if it's either both or instance or system,
so based on what you want,
and then for one consecutive period of five minutes.
Here's the alarm name
and here's a sample metric data.
So as we can see,
we are zero because the alarm state hasn't been triggered
but if there was an issue with the status check,
then this would go to one.
And so for one consecutive period of five minutes,
then this would trigger the alarm.
So I will click on create
and something is wrong because it can only be done
on the status check failed system, of course.
So let's go onto status check failed system, here we go.
And now we have the recover action, click on create,
and now this CloudWatch alarm has been created.
So what I'm going to do is, again,
go into my CloudWatch alarm.
So let's click on CloudWatch, here, alarms.
And yes, I'm gonna go directly
into CloudWatch alarms from here.
And we can see that we have one alarm right here
which has insufficient data,
so very soon it's going to be okay.
So let me wait until it is okay and green.
My alarm is now in the okay state and so I can click on it,
and as we can see, the actual instance metric value is zero,
but we need a threshold of 0.99.
So I want to go into the alarm state.
So what we can do, though,
is that we can simulate a failure of this alarm
to go into the alarm state and see what happens.
So if I scroll down, as we can see,
we have the history of the actions of the alarm.
So as you can see, we created it
and then it went from insufficient data to okay.
So let's issue an API call to make this alarm
go into the alarm states.
So I'm going to click on CloudShell
to open a CLI directly from within the Cloud
that's going to be properly configured
and that will save me some time,
but you can use this CLI on your own terminal
if you have configured it in the past, okay?
So what I'm going to do is to launch a CloudWatch alarm
and set alarm state.
And I'm going to look at the version two, here we go,
so this is how you run the alarms.
So we need to give the alarm name and the state value
and the state reason, and the state value is alarm.
So let's go into CloudShell.
So first, let's get the alarm names.
So the alarm name is right here, so I'm going to copy this.
So I will type AWS CloudWatch set alarm state
and then the alarm name is the one I just copied right here,
and the alarm state is going to be alarm,
and so sorry, state value is alarm and state reason,
so let's just change this.
So state value is alarm and state reason is,
and I will just say, testing recovering action.
Press enter
and this is going to set my alarm into the alarm state.
So let's refresh this.
And as you can see now, the alarm is an alarm.
And so if we scroll down and look at the actions,
there's going to be a notification
and the alarm went into the alarm state.
And so, if we look at the history right here,
so here's what I want to show you, sorry.
So the alarm went from okay to an alarm
and then two actions happened.
There was a SNS message sends to an SNS topic right here
and also, the second action that was executed
was successfully executed action, ec2 recover.
So my ec2 instance right here has been recovered,
thanks to this action.
It's not something that we can really, really see
how it was being recovered, okay?
But as we can see,
we have the alarm status 1/1 in alarm,
and then the ec2 instance has been recovered
so it'll take a bit of time to be recovered entirely,
but at least it shows you
that when this alarm was being triggered,
then the recovery action was being launched, okay?
So that's it for this lecture.
You could also launch correct another alarm as an exercise,
and this one on the instance,
and then reboot the ec2 instance as an action,
and you can try it out and also set the alarm state,
but for now, we're good to go.
What I'm going to do is just delete this alarm right here.
I can close CloudShell, I don't need any more for now
and then I'm good to go.
So that's it for this lecture, I hope you liked it,
and I will see you in the next lecture.