简体   繁体   English

如何停止 Amazon Aws EC2 实例?

[英]how to stop Amazon Aws EC2 instance?

I'm trying to write a script to stop several instances in our test environment on Friday and have them start back on Monday, to save little cost.我正在尝试编写一个脚本来在星期五停止我们测试环境中的几个实例,并让它们在星期一重新开始,以节省很少的成本。

Is there a way to stop instances by IP addresses (and not by instance ID), or some other way I don't know about?有没有办法通过 IP 地址(而不是通过实例 ID)或其他一些我不知道的方式来停止实例? (The reason being that instance ID's may change if an instance had to be deleted and recreated.) (原因是如果必须删除和重新创建实例,则实例 ID 可能会更改。)

This is a zero code solution:这是一个零代码解决方案:

Put your instances into autoscale groups and add a shutdown and startup schedule on the autoscale group.将您的实例放入自动缩放组,并在自动缩放组上添加关闭和启动计划。 This can be done in the AWS console.这可以在 AWS 控制台中完成。

This can also be automated using the AWS CLI.这也可以使用 AWS CLI 自动化。

Use EC2 Tags to give your instances key/value tag pairs, then write a script using Boto which searches for instances with the right tags, and then terminates them.使用 EC2 标签为您的实例提供键/值标签对,然后使用 Boto 编写一个脚本来搜索具有正确标签的实例,然后终止它们。

You could also use Boto to list instances matching the specific IP address, and terminate them that way.您还可以使用 Boto 列出与特定 IP 地址匹配的实例,并以这种方式终止它们。

But... IP addresses are dynamically assigned (unless you are using Elastic IPs).但是... IP 地址是动态分配的(除非您使用的是弹性 IP)。 So why not make a note of the instance IDs when launching the instances, instead of the IP address?那么为什么在启动实例时不记下实例 ID,而不是 IP 地址呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM