How can I kill all my instances from the command line? Is there a command for this or must I script it?
To terminate an instance using the consoleOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Instances. Select the instance, and choose Actions, Instance State, Terminate. Choose Yes, Terminate when prompted for confirmation.
kill command The command for that is simply 'kill' followed by the process ID. In the below screenshot, I have mentioned the PID of firefox application which I had started earlier. The default command 'kill' sends signal to the process to be terminated.
This is an old question but thought I'd share a solution for AWS CLI:
aws ec2 terminate-instances --instance-ids $(aws ec2 describe-instances --filters "Name=instance-state-name,Values=pending,running,stopped,stopping" --query "Reservations[].Instances[].[InstanceId]" --output text | tr '\n' ' ')
If hackers have disabled accidental instance termination, first run this command:
aws ec2 describe-instances --filters "Name=instance-state-name,Values=pending,running,stopped,stopping" --query "Reservations[].Instances[].[InstanceId]" --output text | xargs --delimiter '\n' --max-args=1 aws ec2 modify-instance-attribute --no-disable-api-termination --instance-id
AWS Console and Elasticfox make it pretty easy.
A command-line solution can be achieved in one-line using the EC2 API tools:
for i in `ec2din | grep running | cut -f2`; do ec2kill $i; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With