我如何能杀死在命令行中所有的EC2实例?有的、命令行、实例、能杀死

2023-09-11 08:25:33 作者:好看好听的八字:人潮拥挤我陪你走

我如何能杀死在命令行中我所有的实例?是否有一个命令为这个或必须脚本呢?

How can I kill all my instances from the command line? Is there a command for this or must I script it?

推荐答案

据我所知,没有一个全开关为EC2-终止-instances命令。所以,你可能需要的脚本它。它不会那么难。你只需要生成一个逗号分隔的实例列表。

As far as I know there isn't an 'all' switch for the ec2-terminate-instances command. So you probably need to script it. It won't be that hard. You only need to generate a comma separated list of your instances.

这是我使用的是python脚本:

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()

它使用博托库。这是没有必要的特定任务(一个简单的外壳脚本就足够),但它可能是方便的,在许多场合。

It uses boto library. This is not necessary for the specific task (a simple shell script will be enough), but it may be handy in many occasions.

最后,你是否知道Elasticfox Firefox扩展的?这是迄今为止访问EC2最简单的方法。

Finally are you aware of Elasticfox extension for Firefox? This is by far the easiest way to access EC2.