Terminating and EC2 instance by command line

0 votes

Is it possible to terminate all my EC2 instances at once using command line? If yes what is the command? 

Aug 9, 2018 in AWS by datageek
• 2,440 points
25 views

1 answer to this question.

0 votes

There is no command to terminate all instances at once. So you probably need to script it.You only need to generate a comma separated list of your instances.

This is a python script I am using:

import sys
import time
from boto.ec2.connection import EC2Connection

def main():
    conn = EC2Connection('', '')
    instances = conn.get_all_instances()
    print instances
    for reserv in instances:
        for inst in reserv.instances:
            if inst.state == u'running':
                print "Terminating instance %s" % inst
                inst.stop()

if __name__ == "__main__":
    main()

answered Aug 9, 2018 by Archana
• 4,090 points

Related Questions In AWS

0 votes
1 answer
0 votes
2 answers

How to configure Amazon EC2 command line interface?

You can use this command to create ...READ MORE

answered Feb 23 in AWS by Shashank
• 1,350 points
108 views
0 votes
1 answer
0 votes
1 answer

Stopping then starting EC2 from command line

I understand this post is 3 years ...READ MORE

answered Aug 24, 2018 in AWS by Priyaj
• 56,940 points
84 views
+3 votes
5 answers

How to move files from amazon ec2 to s3 bucket using command line

Hey, 3 ways you can do this: To ...READ MORE

answered Oct 9, 2018 in AWS by Omkar
• 67,660 points
3,976 views
0 votes
1 answer
0 votes
1 answer

Create Amazon EC2 instance with API

If you are looking for a method ...READ MORE

answered Jul 20, 2018 in AWS by Archana
• 4,090 points
108 views
0 votes
1 answer

How to set up a SPF(Sender Policy Framework) for AWS EC2 instance?

Setting up a SPF record is pretty ...READ MORE

answered Aug 16, 2018 in AWS by Archana
• 4,090 points
251 views