Here and welcome back into this video we'll be discussing about the auto's killing Life-cycle no in
definitive terms, or does killing Life-cycle Hook allow us to have a control or the instance launch
and termination state with the auto killing up?
So with the definition, it becomes a little confusing.
So let's understand this.
A simple use case.
So let's say that you have a use case where you have an auto scaling group and within the auto scaling
group you will have instances which will scale out and scaling back again depending upon this killing
policies that you might have.
Now you have it easy to instance there, which is scheduled to be terminated.
Let's say that you is giving policy very first.
CPU utilization is greater than 70 percent.
Then the instance will be launched.
I mean, the new instance will be launched.
Now, order past a minute.
Or do you have realized that the average CPU utilization has gone down?
That means the scaled out instances would soon be terminated.
So that is the first point of it.
So what typically you might need is you want to backup all of the logs of that easy to instance to a
dabblers S3 and also run some deregistration scripts order so that it did adjust itself from various
centralized services that might be present.
So generally, an enterprise is a single easy to instance, might be registered with central servers,
it can be EDI, it can be spacewalk, it can be Nessa's, etc..
So typically Wednesday instances terminated.
You want that instance to be data stored.
So that is the second step.
And the problem that used to happen was one instance got terminated in that instance would still be
present within the console of it, within the console of space walk, etc. and it becomes a little difficult
to identify which instance is still running and which instances terminated from the central services
console.
So that is the second important requirement.
And the third important requirement is then you can go ahead and terminate the instance once the second
step is completed.
So Lifecycle who basically allows us to achieve this use case.
So this is one of the uses use cases that you can do.
There are several others, but we have taken this simple one for demo purposes.
So if you look into the overall diagram of the lifecycle who thanks to Idalis documentation for this.
So let's understand this.
You have auto scaling group audio, so you have a skill out even that happens during skill, not even
a new easy to instance gets launched.
All right.
So initially it would be independent day and then it would go inservice.
So we are not discussing about the lifecycle Hungaria.
So there are two lifecycle, even Sawaya.
One is on the right hand side here and second is on the left hand side, which is the termination one.
So at the upper one, this lifecycle look, it's typically when a new AC2 instance gets launched and
the bottom one is when easy to instant's gets terminated.
Alright, so let's start from the beginning.
You have all the scaling.
Look, there is a scale out even that happened.
So a new easy to instance got launched.
So it goes into the pending stage earlier.
We are not considering lifecycle hook right now.
So after bending state it goes into inservice state.
That means everything is up and running.
After that you have a scaling event that happens.
That means the CPU utilization or the workload got decreased.
So now you have the terminating state and from terminating stage you have terminated this.
All right.
So now the use case that we discussed, that use case was associated with determinately stage of the
lifecycle.
So now what happens is that currently this new you see two instances in service.
Now a scaling has happened and it is going to terminate.
Now, if you have a lifecycle hook, then the policy will go to the terminating of it.
If you do not have this lifecycle, then the instance will automatically be terminated.
Now, since you want a solution where all the logs should be backup and some de-registration scripts
should run, we need to have a lifecycle hucko area.
So let's say that we have a lifecycle hook Golez terminating it.
So now what will happen is that easy to instant's will not get terminated at this specific stage.
After this specific stage complete and you have the termination proceed, then only the instance will
get terminated.
All right.
So at this specific stage, you can go ahead and transcripts, which can.
Back up the logs and which can be registration's good at this specific stage, once your automated script
has completed, it can go to the termination proceed stage and it can be terminated.
Similarly, if you have something, let's say you want to run certain scripts before the instance goes
into service.
You can have a lifecycle hook for bendingly where you can run some kind of automation once it is completed
and then it goes to the pending proceed stage and then it will go in service.
So this is the high limit order.
Let me show you in screenshot, Representative, on how exactly one of these states really looks like.
So in this state, this is the step one where the instance is awaiting termination.
That basically means that this Kileen status of ocurred and the instance is in this specific state,
which is terminating it.
Now, if you look into the screenshot, it basically states that waiting for terminate life action.
And it is basically telling is that it is terminating easy to install and this is the easy to enforce
it.
Now, it has not yet terminated it because it is still in this specific terminating stage.
Now, at this stage, you can tell what the automation scripts that you might want to run, you might
want to run data distribution scripts, or you want to remove the DNS record associated with the instance
before it gets terminated.
So that is something that you can do now.
Once all of your automation and everything has completed, then there can either be a timer.
Let's say after one night it will automatically go to the terminating procedure state.
Or you can send a specific EPA call saying that all the automation in this specific state has completed
and the instance can now be terminated.
So this is the first stage.
Second stage is where we're basically running a similar mine.
And Selectwoman is basically it states that.
All right, all my automation script has successfully been executed.
All the logs has been up, all the registration scripts has completed.
Now, you can come out of that terminating late stage and you can go ahead with the termination of the
easy two instance.
So if you look into this year like I'm on, it basically states that the life cycle at the end result
as continue.
And it says that the instance it is this specific one, if you see it, is seven, five, three.
And if you look into this screenshot, this is the instance which is scheduled to be terminated.
All right.
So once your automation has completed you, you can tell it to continue after it discontinued.
It goes through the termination procedure and it is terminated.
And you see in the third stage, once you have given the go ahead, you see you have given a go ahead
of what you are saying, that you can go ahead and continue, then the auto scaling group will go ahead
and terminate the easy to instant's.
So this is what basically the lifecycle hooks are all about.
Now, this hope that we were discussing is about terminating.
You also have a which is used during the instance launch.
So this is something that you need to remember for the exams because there might be a question related
to this.
So let's do one thing.
Let me quickly show you and how this might look in the console, because things are boring without practicals.
So this is my easy to instant's.
Now, this easy to answer is if you look into the security, it is actually part of Auto's Killinghall.
So let's go to the auto scaling group over here.
Now, within this auto scaling group, you have one instance.
The desired is one minimum and maximum is two.
So let's do one thing.
Let's take this specific group.
And what else say I see desired as zero, like I say, minimum as zero as well.
And you can see.
All right.
So now you see, if you just open up this info box, it basically states that the instance maybe in
the process of launching or terminating in order to match their desired capacity.
Now, since the desired capacity, we changed from one to zero.
That basically means that the instance would be in the terminating stage.
So if you looking to design the AR during the terminating stage, if you have the lifecycle hook, it
goes to the terminating the state.
Now, in my case, I do have a lifecycle and due to the lifecycle hook, you see the instance state
currently is terminating, which it has not yet been terminated.
So let's quickly verify if this holds true.
True, currently, you see the instance has not yet been terminated.
Now, if you wonder whether Life-cycle hooks up, so if you click on the life hooks that there is one
simple life-cycle hook which is created.
Now, if I click on Create Life-cycle Hook, there are two life-cycle hooks which are available.
One is instance launch antagonist instanced determinate and you also have the heartbeat timer.
So basically it will wait for a certain amount of seconds for the instance to be indeterminate which
state.
And after that timeout completes or after using continue a at the instance would come out of the terminating
the stage and it would be terminated.
So if you look into the activity history, Aurier, let me let me just remove the Abbo info message
because it is minimizing the screen.
Great.
So now it is much more visible.
So currently you see it says that waiting for template lifecycle action, that means that this specific
instance, which is for one, if B it would be the same one for one, if be this instance is scheduled
to be terminated, it is not terminated because there is a 30 minute wait action lifecycle, which is
ongoing.
So let's assume that all of our automations scripts has been executed successfully.
And we are good to go with terminating in sense because you do not really want big instances to be running
for next one hour even after your automations script is completed.
So you you want them to be terminated.
So in order to terminate, it will have to call back or let's try it.
So I'll go to the sequences.
So I'm in my AC2 instance, Seela, and basically I'll copy one of the CLIA commands.
So what this really does is, you see it is either this or auto scaling, then you have complete a lifecycle
action, then the lifecycle hook name is but terminate hook.
So this is basically the lifecycle hook Nymboida.
So this is the hope that you want to continue.
Then you have the auto scaling.
Rupnik So this is the auto scaling Rupanyup where this hook is associated, then the Lifecycle Action
Reserve, you want to continue and then you have to specify the instantiating.
So let's replace the instance idea or it quickly.
So let's go it up, the intensity
and you have the region, once you have done that, you can go ahead and run this guy and everything
has been successful.
And you see it automatically states that this system is going down for the power of stage.
And basically now if you look into the instances.
And once you refresh it, you see that we need to wake Life-cycle children to terminate policy and within
the activity history, within a minute or two, you will see that this specific instance would be terminated.
So currently it is shutting down and then it will be terminated.
So I hope you understood what the auto scaling life-cycle hooks are all about.
Again, this is quite important.
Specifically, if you are having auto scaling in enterprises and you want to do a lot of data destruction.
In fact, in the organization that I have been working that we used to extensively use this ruminating
late stage so that are instance of data just from various monitoring services that we had anyway.
So that's the high level worldview.
I hope this video has been informative for you and I look forward to see you in the next video.