我有一个长时间的批处理作业,我想在 AWS EC2 Spot 实例上运行,以节省资金。但是,我找不到两个看似关键的问题的答案:
创建新实例后,我需要将代码上传到其中、配置它并运行代码。对于自动和无人值守创建的 Spot 实例,这是如何完成的?
当实例停止时,我更喜欢有某种类型的通知,以便可以保存状态。 (这并不重要,因为如果突然终止批处理作业会正常运行 - 但最好是干净关闭)。
部署 Spot 实例的标准方法是什么?有没有办法手动设置,把它变成现货实例,然后让它休眠直到现货价格可用?
最佳答案
至于 #1,如果您创建一个 AMI(亚马逊机器镜像),您可以将您想要的所有内容预安装在一个“休眠”镜像上,您可以将其用作您启动的 spot 镜像的基础:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-getting-started.html
对于 #2,当 spot 实例使用 SNS 终止时,您会收到通知:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-autoscaling-notifications.html http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/ASGettingNotifications.html
顺便说一句:您可以收到实例终止的通知,但只有在它终止之后。您无法收到实例即将关闭的通知并优雅地保存状态 - 您需要设计您的解决方案以应对意外关闭。
No matter how high you bid, there is always a risk that your Spot Instance will be interrupted. We strongly recommend against bidding above the On-Demand price or using Spot for applications that cannot tolerate interruptions.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-protect-interruptions.html
关于amazon-web-services - EC2 Spot 实例 : How to start tasks, 如何停止它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25755123/