简体   繁体   English

通过HTML / Python / Bash脚本停止AWS EC2实例

[英]Stopping an AWS EC2 Instance through HTML/Python/Bash Script

Is there any way to send a button/hyperlink in an email through HTML which will trigger a Python/Bash Script which will stop a running EC2 instance ? 是否有任何方法可以通过HTML在电子邮件中发送按钮/超链接,从而触发Python / Bash脚本,从而停止正在运行的EC2实例?

I am basically going through all running instances, checking their uptime through Fabric -> SSH and then sending a mail when the uptime has been beyond a specified limit. 我基本上会检查所有正在运行的实例,通过Fabric-> SSH检查其正常运行时间,然后在正常运行时间超出指定限制时发送邮件。

If it is not possible through a script, is there a specific hyperlink for every instance which triggers its stopping ? 如果无法通过脚本进行操作,则是否为每个实例触发了停止实例的链接

PS: I know about Amazon CloudWatch but am searching for an alternative since I would have to create an alarm for every instance manually through cloudwatch. PS:我了解Amazon CloudWatch,但正在寻找替代方案,因为我必须通过cloudwatch为每个实例手动创建警报。

PS-2: I don't require the whole code. PS-2:我不需要完整的代码。 Any help in this direction will be appreciated. 对此方向的任何帮助将不胜感激。
Example : What frameworks can be used ? 示例:可以使用哪些框架? etc. 等等

For handling amazon instances you probably want to use boto which provides most of the common needed functionality. 为了处理亚马逊实例,您可能需要使用提供大多数常用功能的boto It is very important to read the documentation since data loss is a possibility. 阅读文档非常重要,因为可能会丢失数据。 Consider starting here . 考虑从这里开始。

To figure out how long the instance was running you can use instance.launch_time . 要确定实例运行了多长时间,可以使用instance.launch_time

To stop an instance you can use instance.stop : 要停止实例,可以使用instance.stop

Stops an Amazon EBS-backed instance. 停止由Amazon EBS支持的实例。 Each time you transition an instance from stopped to started, Amazon EC2 charges a full instance hour, even if transitions happen multiple times within a single hour. 每次将实例从停止状态转换为启动状态时,即使一次在一小时内发生多次转换,Amazon EC2也会收取完整的实例小时费用。

You can't start or stop Spot Instances. 您无法启动或停止竞价型实例。 (more in link...) (更多链接...)

To terminate an instance use instance.terminate : 要终止实例,请使用instance.terminate

Shuts down one or more instances. 关闭一个或多个实例。 This operation is idempotent; 此操作是幂等的; if you terminate an instance more than once, each call succeeds. 如果您多次终止一个实例,则每个调用都会成功。

By default, Amazon EC2 deletes all EBS volumes that were attached when the instance launched. 默认情况下,Amazon EC2删除实例启动时附加的所有EBS卷。 Volumes attached after instance launch continue running. 实例启动后附加的卷继续运行。

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

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