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,540 points
960 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,170 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, 2019 in AWS by Shashank
• 1,370 points
1,160 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
• 58,020 points
3,112 views
+3 votes
6 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
• 69,220 points
19,992 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,170 points
1,057 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,170 points
1,632 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP