如何避免在 EC2 上因未使用时间而被计费?
我有一个定期任务需要在 EC2 上运行。该任务的运行时间不会超过 10 分钟,我不想最终为该任务闲置的另外 50 分钟付费。根据我的理解,如果我启动一个实例并运行此任务,无论我是否使用任何资源,我都会按使用量付费。因此,我希望每 60 分钟左右做一些事情(只是一个高级草图):
def invokeTimer(i):
if timer(i) expired:
copyDataFromNode(i)
killNode(i)
while True:
for i in range(1,10):
startNode(i)
# Allow the node to boot up
startScript(i)
invokeTimer(i)
sleep(60000)
假设我能够传达我的想法,是否有一种好的方法可以以干净的方式实现这一点,或者可能是教程可能有帮助吗?
I have a periodic task that I need to run on the EC2. This task will not take more than 10 minutes to run and I do not want to end up paying for the other 50 minutes that this task will be idle for. From my understanding, if I start an instance and run this task, no matter whether I use any resources or not, I will be billed for my usage. So I was looking to do something on the following lines every 60 minutes or so (just a high-level sketch):
def invokeTimer(i):
if timer(i) expired:
copyDataFromNode(i)
killNode(i)
while True:
for i in range(1,10):
startNode(i)
# Allow the node to boot up
startScript(i)
invokeTimer(i)
sleep(60000)
Assuming that I was able to convey my idea, is there a good way of implementing this in a clean fashion or perhaps a tutorial that could be of help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 picloud 并按秒付费。
Try picloud and pay per second.
无论您做什么,您都将支付一小时的费用。
一旦启动 EC2 实例(您将它们称为节点,但这是错误的),您就需要支付一小时的费用。任何不足一小时均按整小时计费。
如果您拍摄机器的 AMI(备份映像),则必须为 EBS 卷付费,因此这也是有成本的。
最好的选择是使用竞价实例,这样可以比常规实例节省一些钱。
You will pay for the full hour no matter what you do.
As soon as you start an EC2 instance (you refer to them as nodes, but that's wrong), you pay for an hour. Any partial hour is billed as a full hour.
If you snap an AMI (backup image) of a machine, you have to pay for the EBS volume, so there is a cost there as well.
Your best bet is to use spot instances to save some money over regular instances.