What is AWS Lambda Pricing Based On?

There are two key metrics for AWS Lambda pricing and charges:

Function invocations and execution duration time.

Whenever a function gets invoked, AWS charges $0.0000002 per request, which means one million requests for $0.20. After that, another charge begins the count according to the duration for the completion of execution.

Nine-Tenths of a cent per 100 milliseconds will be charged. The amount will depend on how much memory has been allocated to the function. As an example: a function with 1 GB allocated is going to cost $0.000001667 per 100 milliseconds. This means that it charges $16.67 for 1 Million requests lasting 1 second each.

The time of function execution is rounded up to the next multiple of 100. As an example: If the duration is 457 milliseconds, Lambda will round it up to 500 to get the cost.

How to estimate AWS lambda pricing?

  • AWS Lambda pricing is pay only for what you use model.
  • Your Lambda cost is calculated based on number of requests and the duration.
  • The minimum interval is 100 milliseconds.
  • Memory allocation is another parameter for cost. Increase in memory brings increase in CPI available that brings more cost to your function.
  • The AWS Lambda free usage tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month.

 

 

Free tier

One Million invocations are provided by AWS and four hundred thousand GB-seconds of execution time is given for free per month.

The expiration of this free tier is not upon one year of account creation, like most of the other services. This implies that developers may carry on enjoying the free tier for an unlimited duration.

No legitimate guarantee is in place, though, stating that AWS shall keep its free tier always available.

Additional costs

+Event Sources

In order to get Lambda working, an invocation of some sort should be made. The invocation is an event source. A number of such sources come free, while others get added up to the final cost of execution.

Some examples of free event sources:

Lambda API to invoke a function directly

CloudWatch Rules to invoke a function regularly

AWS lambda pricing

Some of the event sources adding to Lambda charges:

DynamoDB Streams trigger (database)

Kinesis (stream processing)

API Gateway

SQS (message queue buffer)

lambda pricing

Lambda automatically saves every log which is generated by applications working on the platform in CloudWatch Logs. It is very important to keep track of logs, so that you can control and keep watch over functions runtime and whatever might get wrong.

CloudWatch Logs takes charges according to generated data and charges for storage as time goes by. CloudWatch Logs automatically deletes old logs that have expired.

+Retries

When an error occurs after invocation Lambda will retry the same request a couple of times. This is its Retry Behavior, where every try is charged as a normal request. The final Lambda execution cost depends on how many errors are made during transient failures or until the end time.

AWS Lambda Pricing vs. EC2 Pricing

Let’s say an application runs on the AWS US-East (Ohio) region. One million requests are made per month, each during, on average, two hundred fifty milliseconds. The entire workload needs 2 GB of RAM.

Upon running the application on Lambda and on EC2, let’s check the differences:

Lambda

Invocations 1,000,000 x $0.0000002 = $0.200
Execution time 1,000,000 x roundup (250/100) x $0.000003334 = $10.002
Total cost $0.200 + $10.002 = $10.202

EC2

Cost per usage-hour  $0.0188
Number of hours  30 days x 24 hours = 720
Total cost  $0.0188 x 720 hours = $13.536

Now we’ll consider an EC2 instance working on a similar OS as Lambda, and Lambda which runs on Amazon Linux.

In order to get the exact memory size which is 2 GB and the same vCPU allocation of the Lambda function, t3a.small it is chosen as an EC2 instance.

Also using the EC2 on-demand pricing and considering that the application stays online for twenty-four seven, which is best to go with Lambda pricing model.

Cost per usage-hour $0.0188
Number of hours 30 days x 24 hours = 720
Total cost $0.0188 x 720 hours = $13.536

Comparison (Lambda Vs. EC2)

Regardless of the fact that Lambda offers a lot of benefits compared to EC2, like being fully manageable and greatly available and scalable, it can still be less expensive than having to provision and maintain our own server instances.

To be fair, in comparison, it is to take a cluster of four EC2 servers as a minimum: a number of servers of two different Availability Zones. By doing so we reach a level of availability the same as that of Lambda.

Only that way can a quadruple EC2 costs and management work be reached. Also, taking the requirement for a Load Balancer and an Auto-Scaling service, its total cost would be five or six times greater than Lambda.

Advantages of the Lambda Pricing Model

~AWS Lambda pricing model eliminates waste with idle resources.

~Payment is only required when a function is invoked.

~No matter how much time passes, without invocation, it will cost nothing.

~Even after the passing of that time, the function remains completely available.

~It offers reduced financial risks, which is of great benefit to SMEs and startups.

~It offers high availability for free.

Downsides of AWS Lambda Pricing Model

~If a workload has a difficult predictable duration, Lambda can raise financial risks.

~ In case of increased execution time, the total cost shall also increase proportionally.

~No economies of scale are available as demand grows because pricing is completely variable to application demand.

~Having a single-purpose user request invoke multiple functions, costs and latency could thus add up.

See Also

Lambda Configuration

AWS lambda cost calculator