Lambda Billing for api code

0

I am trying to figure out api billing, if my api script is running does it incur runtime charges waiting for requests to come in, or runtime charges only apply when requests come in and the script serves them. It is a Python flask api script.

Boris
asked 5 months ago186 views
2 Answers
0
Accepted Answer

In Lambda you only pay for the number of invocations and actual duration, i.e., from the time your function receives a request until it returns an answer. If there are no API calls, you pay nothing.

profile pictureAWS
EXPERT
Uri
answered 5 months ago
profile picture
EXPERT
reviewed 25 days ago
profile pictureAWS
EXPERT
reviewed 5 months ago
  • That makes sense, the api process is idling when waiting for requests and no cpu cycles are allocated to it. It seems that should be a general rule: idle processes don't incur charge. Say you receive a request on AWS deployed api, but your AWS deployed api makes an api search request to say SummoLogic, which takes 10mins to complete and return search results. In those 10mins AWS cpu is not allocated as the search api is waiting for a response, SummoLogic's cpu is doing the work, so you shouldn't get charged by AWS for those 10minutes..?

  • Well, that's not how it works. You are charged from the time your handler is invoked until it returns. When it returns we freeze the sandbox and nothing can run in there. While it is in the handler, even if your function is waiting for some external resource, the CPU is still allocated to you and you are charged for that time.

0

Thank you for the clarification, even if your process is in wait or ready state (not in running state) you get charged for the runtime that never ran. Kind of like renting a car, when the car is parked you still get charged. Does runtime charge only happed when code is deployed or also while developing, if you have AWS console open and you are typing commands there, do you also get charged for that time as well?

Boris
answered 5 months ago
  • You can create many functions. You are only charged when you actually invoke them. SO as long as you are in the console writing the code, nothing happens. Only when you invoke the function, either directly by calling the Lambda Invoke API, or by invoking some other service that triggers your function such as API Gateway. Again, you are only charged from the time your handler is called until it returns (some exception with Lambda extensions, but not relevant for this discussion).

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions