Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does AWS charge for lambda in sleep state

For instance:

count = 0
        while True:
            try:
                if count == 5:
                    break
                snap = ec.create_snapshot(
                    VolumeId=vol_id,
                    Description=instance['InstanceId']
                )
                break
            except Exception as e:
                print(e)
                sleep(180)
                count = count + 1

So If I have lot of instances and errors then it could be long time of running lambda. What could be alternative to put Lambda to sleep?

like image 604
Janis Karklins Avatar asked Sep 15 '17 15:09

Janis Karklins


People also ask

Does AWS charge for Lambda?

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume—there is no charge when your code is not running.

Does Lambda charge for cold start?

In this diagram, the first two steps of setting up the environment and the code are frequently referred to as a “cold start”. You are not charged for the time it takes for Lambda to prepare the function but it does add latency to the overall invocation duration.

How you are charged when using AWS Lambda?

With Lambda, you can run code for virtually any type of application or backend service, all with zero administration, and only pay for what you use. You are charged based on the number of requests for your functions and the duration it takes for your code to execute.

Can AWS Lambda run continuously?

Lambda has a hard timeout of 15 minutes. Therefore it cannot run continuously.


2 Answers

Yes you are still charged. Calling sleep() does not stop the execution environment. You pay for the duration of the execution environment, from the time the function is invoked until the time the function finishes executing (or until it reaches the configured timeout).

like image 81
Mark B Avatar answered Sep 20 '22 05:09

Mark B


My assumption is yes they do. AWS Lambda charges based on three factors

  1. Allocated memory to function
  2. Number of Executions
  3. Compute duration

If you look at the definition of how duration is calculated.

Duration is calculated from the time your code begins executing until it returns or otherwise terminates, rounded up to the nearest 100ms. The price depends on the amount of memory you allocate to your function. You are charged $0.00001667 for every GB-second used.

AWS calculates charges from the time your code begins executing, to the point at which it returns/terminates.

like image 23
Preston Martin Avatar answered Sep 21 '22 05:09

Preston Martin