I've been digging into AWS a LOT lately. The best way to learn something is to get your hands dirty. This is a quick guide on how to find and terminate EC2 instances using the AWS CLI v2.
This guide assumes that you already have the AWS CLI installed and configured. If you don't, check out this guide.
Finding EC2 Instances
To list all your EC2 instances, you can use the describe-instances command:
This command returns a table that lists the Instance IDs, their current states, and their associated Name tags.
Terminating an EC2 Instance
Once you identify the EC2 instance that you wish to terminate, note down its InstanceId. To terminate an instance, you use the terminate-instances command:
Replace i-1234567890abcdef0 with the actual InstanceId of the EC2 instance you wish to terminate. After you run the command, the instance will start to shut down.
Check your work
It may take a moment for the instance to fully terminate. You can check the status of the instance by running the describe-instances command again:
Conclusion
That's it! You now know how to find and terminate EC2 instances using the AWS CLI v2.