Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid getting billed on EC2 for unused time?

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?

like image 935
Legend Avatar asked Dec 16 '22 11:12

Legend


2 Answers

Try picloud and pay per second.

like image 135
ThinkCode Avatar answered Dec 23 '22 16:12

ThinkCode


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.

like image 43
GregB Avatar answered Dec 23 '22 14:12

GregB