Instructor: One very important question exam you may get
is the wait condition did not receive the required number
of signals from an Amazon EC2 instance.
And you need to be able to troubleshoot this.
So number one, it's maybe because the AMI you're using
has the CloudFormation helper scripts installed.
So not installed you need to make sure that he has them.
Obviously if it doesn't have the helper scripts,
you go online documentation and you figure out
how to download them to your instance.
Then you need to verify that the cfn-init
and cfn-signal commands were successfully run
on the instance.
And as we see their logs, such as /var/log/cloud-init.log
or /var/log/cfn-init.log, to help us debug
the instance launch, very important.
Then we can retrieve the logs by logging directly
into our instance using SSH.
But as we'll see in this lecture, we won't
be able to do so until we prevent a delete instance
on failures.
So we'll see this in the next lecture but in this lecture
we'll see how things would not work
which will be quite cool.
And then finally, a very tricky one is that
to your instance must have a connection to the internet
and so if it's in a VPC basically our instance
should have internet connection we achieve
through a NAT device,
if it's the private subnet or through an internet gateway
if it's in a public subnet.
And we'll see this in details when we do the EPC section
but the idea is that if our instance can not talk
to the internet it can not talk to the CloudFormation
service and if it can not talk to the CloudFormation
service well there's no way for the CloudFormation
service to receive a signal and things won't work.
And so for an example, if you want to know
if you have access to the CloudFormation service,
from the instance you can run a curl command
on the aws.amazon.com, very simple.
So let's go have a look at how it can trigger
a failure for the wait condition.
Alright, so in CFN-signal failure,
that I'm on now, it is look like the exact same thing,
but the thing that is a failure
is that my command, hello, will say "boom,"
and then will exit with error code one.
And so when you do exit one,
that means that is a bad exit code.
The good exit code, zero one is a bad one,
so this will basically trigger a cfn-init failure,
and so it will signal a failure to CloudFormation.
And so, let's go see what happens in that case.
So we go to our stacks, we create the stack,
we're going to upload our failure stacks,
so it's number six, here we go,
and click on next.
Now I'll just say cfn-signal failure example
as the search key, still will be the same,
and next, and all the way to the bottom, create stack.
Alright, so now, we are going to have to wait
just a little bit,
and I'll pause the video for the EC2 instance
to get created and to so report a failure,
cause we can see my instance is not creating progress,
if I go to my EC2 management console,
I should be able to see yes my instance running.
So now should be calling cfn-init,
and we should wait for it to happen.
And so, my wait, my sample wait condition,
again, is still in progress,
so it's waiting for a signal, basically.
So now I'll just refresh and wait a little bit,
my instance is now created.
So cfn-init should be running within a minute,
and here we go, we get a failed to receive
one resource signal within the specified duration.
So I think that was even a time-out for this one,
not even the cfn signal thing in it.
So we failed to receive a signal
within the specified duration,
so create failed for the sample wait condition,
and as a result, my entire cfn-signal
instance and stack is going to roll back.
Roll back means that my instance
is going to be deleted,
and so will my sample wait condition.
So now if I go to my EC2 management console,
my instance is shutting down.
And so the cool thing is that,
yes, indeed, if cfn-signal doesn't work,
or if cfn-init doesn't work, or whatever,
then obviously the wait condition fails,
and we're happy, and we should roll back.
But now, the little problem is that
I can't debug why it failed,
because as you can see, well my instance is shutting down,
so that's a little bit of a problem for me, isn't it?
'Cause I can't SSH into it, so we'll see
in the next lecture how to do this,
but the cool thing is that now
we get a sample wait condition that fails,
and so we're able to debug why
no resource signal was being received,
that's because there was an error in our scripts.
So I will see you in the next lecture.