Delete EC2 Instance via AWS CLI

Delete EC2 Instance via AWS CLI

AWS CLI Commands for Deleting EC2 Instances

Table of contents

Tasks

  • Using AWS CLI, delete an EC2 instance named nautilus-ec2 present in the us-east-1 region.

  • Before submitting your task, make sure the instance is in the terminated state.

Steps

  1. Get the instance ID and Stop the nautilus-ec2 instance.

     aws ec2 describe-instances --filters "Name=tag:Name,Values=nautilus-ec2" --query "Reservations[*].Instances[*].InstanceId" --output text
    

    • i-04575360679a33d0b
  2. Delete the EC2 Instance

     aws ec2 terminate-instances --instance-ids i-04575360679a33d0b --region us-east-1
    

  3. Verify the instance state is on terminated state

     aws ec2 describe-instances --instance-ids i-04575360679a33d0b --region us-east-1 --query "Reservations[*].Instances[*].State.Name" --output text
    

    #aws #cloudcomputing #happylearning