- Now, let's review a demo
of stopping and terminating EC2 instances.
Now, from the EC2 dashboard we can go to Instances
and you'll see we have the Linux instance
that we created earlier,
we have a Windows instance that we launched earlier
and then I took the liberty of duplicating
a Linux instance just so we had something to terminate.
So, if we were to look at the actions that we can take,
we can start an instance, stop an instance,
we can do stop, hibernate,
we can reboot and we can terminate.
So, in many cases rebooting may be,
you know, a viable option.
It may be appropriate for that particular application
in that particular scenario.
And so, you can do that right here from the console
just simply cause that machine to reboot
and perhaps, you know,
there's an issue that could be resolved
by simply rebooting the machine
or perhaps you're doing something
with a machine that just requires rebooting
like you know, maybe installing something in Windows
and you can do that.
Otherwise, rebooting simply,
like the machine doesn't go away
and come back it's there
but it's just like a machine on your desk,
if you hit the reboot button
or you go to your you know, start menu or whatever
and you just say reboot, that's essentially what it's doing,
the instance doesn't go anywhere.
Now, in other cases, we may decide you know what,
we don't actually need this machine anymore.
So, we could just say terminate.
If we were to terminate then it will say,
are you sure you want to terminate.
These will be gone, right.
Any storage on any local volumes will be gone,
the EBS volume that's attached will also be deleted.
And of course this one says,
it has termination protection and will not be terminated.
So, before I can terminate it,
I have to go to Instance Settings,
Change Termination Protection,
and say Yes, Disable.
Right, so, it's a safety mechanism,
I'm going to go ahead now that I've disabled that.
Now, I can say Terminate.
And it says this is an EBS-backed instance,
meaning that the root volume
is backed by an EBS volume
and that volume will also be deleted.
Are you sure you wanna do that?
Yes, let's go ahead and terminate that instance.
And so, then it goes into a shutting down state
and then it will go into a terminated state.
And so, that ID we will never see again
because that instance now that we've terminated
it's completely gone and it's a part of our history.
You'll notice down here that we have an instance
that is currently in a stopped state.
Which means that it's not actively running
like the other two are but it still exists.
It hasn't been terminated but it's not running either.
And so, the volume if you scroll down here,
we should see that the root volume still exists,
we still have some type of a EBS root volume
that's still there.
So, we're not paying the hourly fees
for running this machine
but we are paying the monthly storage fees
for that EBS root volume.
And so, there we go that other one is now terminated
and so it will remain here in our console list
for some time and we can also filter out
if we wanted to filter by instance state,
we could say you know what,
I don't want to worry about
those that are currently terminated to stop,
just show me the ones that are running, right.
And so, now we have this Linux instance
and the Windows instance.
So, let's go ahead and stop our Linux machine.
Now, before we do that,
I just wanna point out the difference
between Stop and Stop-Hibernate.
Stop-Hibernate is currently not available
simply because we need to enable that ability
when we launch the instance.
If you don't enable that ability
at the time you launch it then it's just not available.
Right.
So, we did not opt into that at the time
we launched the instance but what that means is again,
stopping it just means that it still exists
but we can get it back, we can restart it, right.
But Stop-Hibernate,
the critical difference between Stop
and Stop-Hibernate is that Hibernate
maintains the contents of memory.
So, when you stop it and then restart it again,
whatever was in RAM gets put back
and so the machine can immediately pick up
where it left off rather than having to wait
for you know, processes to start
and pull information off of disk.
So, let's go ahead and stop it
and you'll notice here it's saying that any data
on the ephemeral storage will be lost.
This instance doesn't really have an ephemeral storage
but if we did,
if we had storage that came with the instance,
not an EBS volume but a volume
that was an intrinsic part of the instance
and any data on that would be ephemeral and would be lost.
So, I'll go ahead and stop that
and then it goes into a stopping state
and any time the state ends in i-n-g,
like we're still paying for this instance.
The second it is within the stopping state,
we're still paying for it.
So, again, any instance state that ends in i-n-g,
we are paying for.
So, as soon as it goes into a stopped state
or a terminated state
then that's when we stop paying for it.
Right, so, now it's stopped,
if I go ahead and clear this filter,
you'll see here that here's the instance
that we just stopped and now
I am no longer paying for those hourly charges.
I have a Windows machine that is still running
and I am paying those hourly charges.
Alright, so, the great thing about stopped instances
is that they're already there.
They're you know,
you have applications are installed and configured
and they're much faster,
generally much faster to become available
than launching an instance from scratch.
So, if I wanted to get this back
and pick up where my application and work left off,
then all I would have to do is say Instance State, Start.
And say, yes start that instance.
And then it goes into a pending state
and now I start to pay those hourly charges again.
And it doesn't take very long at all
for that instance to go from pending to running.
Usually, somewhere around you know,
depending on the whether it's Linux or Windows,
some may take longer than others
but there we go just in less than a minute
it went from a stop state to a running state, alright.
And then like I said earlier
if we determine that we no longer needed these
and we were never going to use them again,
then of course I could go back here
and go to Terminate but these two particular machines
we will continue to use in future demos, right.
So, that is how we can stop, terminate, and start instances.