How To Delete An Instance In AWS

How To Delete An Instance In AWS

When you have many instance created in AWS and you are not using few of them from a long time, now time to clean up and you have to delete the instance from AWS.

It’s quite easy and you need to perform a few quick steps to delete an instance in AWS. An important point to remember here is, when you are terminating an instance, you won’t able to reconnect it once terminated. Once you will terminate an instance it just just takes a very short time to delete it automatically.

In this AWS tutorial, we will discuss how to delete an instance in AWS. Along with this, we will also discuss a few other topics like How long do terminated instances stay in AWS?, How do I reset a terminated instance?, Can we recover terminated EC2 instance? and along with this, we will also discuss What is the difference between terminating and stopping an AWS EC2 instance, Who deleted AWS EC2 instance?, How do I know who stopped AWS EC2 instance?, AWS Terminate Instance, How to terminate an instance using AWS Management Console, How to terminate an instance using AWS CLI.

How To Delete An Instance In AWS

Follow the below steps to quickly delete or terminate the instances in AWS.

How To Delete Terminated Instance In AWS

  1. Locate the instance that you wish to delete or terminate on the Instances page in the Amazon EC2 console.
  2. Right-click on the instance, from the menu, choose Instance State –> Select Terminate option.
  3. Finally, on the next confirmation pop-up, choose Yes to confirm the termination of the AWS instance.

Once, you have terminated the AWS instance, it will take a very short span of time to completely delete from the AWS console.

AWS Terminate Instance

Once, you have decided, you don’t need the AWS instance anymore, you can go ahead and delete it but here the deletion task is nothing but the termination of the AWS instance.

Once you terminate the resource, you can still able to see the resource on the AWS console for another 1 hour approximately from the time of termination. Then it gets deleted automatically from the console.

The most important point is, once you will terminate the AWS instance, the data associated with that particular instance will also get deleted. So make sure to take the backup of your data before terminating the instance.

You can also able to terminate an AWS instance using the  AWS Management Console or the AWS command-line interface.

How to terminate an instance using AWS Management Console

You can easily terminate an AWS instance using the AWS management console following the below quick steps.

  1. The first step is, make sure to take back up of your data before terminating the AWS instance otherwise you are going to lose your data.
  2. Navigate to Amazon EC2 console ( https://console.aws.amazon.com/ec2/).
  3. Choose the Instances option in the navigation pane.
  4. Now choose the Instance state, Terminate instance.
  5. Finally, you will get a confirmation pop-up now, Select the Terminate option for the confirmation.

You can also able to terminate an instance using the AWS CLI.

How to terminate an instance using AWS CLI

You can follow the below quick information to terminate an instance using the AWS CLI.

You can specify the specific instances that you want to terminate.

Syntax

The syntax of the AWS CLI cmdlet to terminate the instance

terminate-instances
--instance-ids <value>
 [--dry-run | --no-dry-run]
 [--cli-input-json <value>]
[--generate-cli-skeleton <value>]

You can provide up to 1000 instance IDs with the AWS CLI cmdlets. But the suggestion here to run with small batches.

Let’s consider the below example that terminates a specific instance with the specified ID.

Example:

You can execute the below AWS CLI cmdlet with the correct instance ID.

aws ec2 terminate-instances --instance-ids i-573790123yhjiuikl

Once you will execute the above AWS CLI cmdlet, you will get the output like below.

{
    "TerminatingInstances": [
        {
            "InstanceId": "i-573790123yhjiuikl",
            "CurrentState": {
                "Code": 32,
                "Name": "shutting-down"
            },
            "PreviousState": {
                "Code": 16,
                "Name": "running"
            }
        }
    ]
}

How long do terminated instances stay in AWS?

Once, you terminate the instance in AWS, it stays 1 hour approximately and then it gets deleted permanently.

How do I reset a terminated instance?

It’s not possible to reset a terminated instance in AWS. Once you have terminated the instance then you can’t use that instance anymore and you have to create a new instance.

Can we recover terminated EC2 instance?

it’s impossible to recover a terminated EC2 instance. Not only that, you won’t able to recover the data also that you might have stored locally.

What is the difference between terminating and stopping an AWS EC2 instance

When you are using an AWS EC2 instance, you have the option to stop and terminate the AWS EC2 instance.

Either you stop the AWS EC2 instance or you terminate the instance, In both cases, the instance will shut down and the VM will be taken away permanently, and then you no need to pay for the usage.

Let’s discuss a few key differences between stopping and terminating the AWS EC2 instance.

Terminating AWS EC2 InstanceStopping AWS EC2 Instanse
The attached bootable EBS volume will get deleted.The attached bootable EBS volume will not get deleted.
The data on your EBS volume will not available after terminating.The data on your EBS volume will remain as it is after stopping.

Note: An important point to note down here is, if you have a plan to start the AWS EC2 instance again, then you should stop the AWS EC2 instance instead of terminating it.

Who deleted AWS EC2 instance?

If you are surprised to see the deletion of any specific AWS EC2 instance and wish to know who has deleted that instance. By accessing the Amazon CloudTrail, you will get to know who is actually responsible for the deletion of the AWS EC2 instance.

How do I know who stopped AWS EC2 instance?

With the help of Amazon CloudTrail, We can able to know who has stopped the AWS EC2 instance. Follow the below steps.

  1. Open Amazon CloudTrail console and choose Event history from the navigation pane.
  2. Select the Event name from the Lookup attributes dropdown menu.
  3. Now the time to enter the event name. You need to enter the event name based on the actual event had occured. For example, incase your instance was stopped, enter the event name as “StopInstances“, if your instance was terminated, enter the event name as “TerminateInstances”.
  4. On the event details page, choose the event name as StopInstances or TerminateInstances. Now you can able to see the name of the AWS Identity and IAM user that actually initiated the event.

AWS ec2 delete-instance cli

You can able to delete an AWS instance quickly using the AWS CLI cmdlet. The AWS CLI cmdlet will delete a specific instance that actually helps you to terminate the related Amazon EC2 instance. An important point to remember here is, make sure to stop an instance before trying to delete it.

Syntax

The syntax is as below

delete-instance
--instance-id <value>
[--delete-elastic-ip | --no-delete-elastic-ip]
[--delete-volumes | --no-delete-volumes]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]

Wrapping Up

Well, in this article, we have discussed How To Delete An Instance In AWS, How To Delete Terminated Instance In AWS, How long do terminated instances stay in AWS?, How do I reset a terminated instance?, Can we recover terminated EC2 instance? and along with this, we have also discussed What is the difference between terminating and stopping an AWS EC2 instance, Who deleted AWS EC2 instance?, How do I know who stopped AWS EC2 instance?, AWS Terminate Instance, How to terminate an instance using AWS Management Console, How to terminate an instance using AWS CLI.