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

Stopping an AWS EC2 Instance through HTML/Python/Bash Script

有没有什么方法可以通过 HTML 在电子邮件中发送 button/hyperlink,这会触发 Python/Bash 脚本,从而停止 运行 EC2 实例?

我基本上遍历所有 运行 个实例,通过 Fabric -> SSH 检查它们的正常运行时间,然后在正常运行时间超出指定限制时发送邮件.

如果无法通过脚本实现,是否有特定的 超链接 触发其停止的每个实例?

PS: 我知道 Amazon CloudWatch,但正在寻找替代方案,因为我必须通过 cloudwatch 手动为每个实例创建警报。

PS-2: 我不需要整个代码。在这方面的任何帮助将不胜感激。
示例:可以使用哪些框架?等等

为了处理亚马逊实例,您可能希望使用 boto,它提供了大多数常见的所需功能。阅读文档非常重要,因为有可能丢失数据。考虑开始 here.

要计算实例有多长运行,您可以使用instance.launch_time

要停止实例,您可以使用 instance.stop:

Stops an Amazon EBS-backed instance. 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.

You can't start or stop Spot Instances. (more in link...)

要终止实例,请使用 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. Volumes attached after instance launch continue running.