本文介绍了AWS EC2停止所有通过PowerShell中/ CMD工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我利用了一些在AWS一次性的服务器,我们期待在努力保持这些降低成本。

I utilise a number of 'throwaway' servers in AWS and we're looking at trying to keep the cost of these down.

首先,我们正在寻找一个相当基本的awsec2停止所有命令将来自我们知道会全天候运行一台服务器按计划运行。

Initially, we're looking for a fairly basic 'awsec2 stop all' command to be run on a scheduled basis from a server we do know will be running 24/7.

经审查,反对什么AWS已经证明,我们似乎需要拉中的所有当前正在运行的情况下,抢ID的这些,然后通过它们传递到命令,而不是简单地陈述我想所有实例关闭。

Upon checking against what AWS have documented, it appears that we need to pull in all the currently running instances, grab the ID's of these and then pass them through into the command, rather than simply stating I want all instances to turn off.

有没有更好的方法收集这些ID的,如仅仅是能够发出停止所有?

Is there a better method collecting these ID's such as simply being able to issue a 'stop all'?

鸭preciate的帮助。

Appreciate the help.

推荐答案

在AWS CLI提供内置JSON与--query选项解析。此外,还可以使用--filter选项执行的唯一正在运行的实例停止命令。

The AWS CLI provides built-in JSON parsing with the --query option. Additionally, you can use the --filter option to execute stop commands on running instances only.

aws ec2 describe-instances \
--filter Name=instance-state-name,Values=running \
--query 'Reservations[].Instances[].InstanceId' \
--output text | xargs aws ec2 stop-instances --instance-ids

这篇关于AWS EC2停止所有通过PowerShell中/ CMD工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 04:10