如何从命令行终止所有 EC2 实例? [英] How can I kill all my EC2 instances from the command line?

查看:25
本文介绍了如何从命令行终止所有 EC2 实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从命令行终止所有实例?有这个命令还是我必须编写它?

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

推荐答案

据我所知,ec2-terminate-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()

它使用 boto 库.这对于特定任务不是必需的(一个简单的 shell 脚本就足够了),但在很多情况下可能会很方便.

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.

你终于知道 Firefox 的 Elasticfox 扩展了吗?这是迄今为止访问 EC2 的最简单方法.

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

这篇关于如何从命令行终止所有 EC2 实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆