AWS Lambda’s Pricing

Christien Kelly
2 min readApr 21, 2023

--

Looking at the pricing for AWS Lambda machines can be very confusing because the prices are difficult to contextualize.

The main point that needs to be taken away is the faster your code runs the lower the cost. The best way to understand is to walk through an example.

For cost references see: https://aws.amazon.com/fr/lambda/pricing/

NOTE

The default billable run time is 100ms. < 100ms == 100ms.

  • If it takes your function 90ms to run lambda will charge for 100ms

Example

Let’s assume we have a 512 GB Lambda cloud function and we are running it 24hours a day. What would it’s cost be?

Let’s make some assumptions about our operations.

cost = $0.0000000083 /ms

function runtime = 100ms

call cadence = 0.5s

// calculation
// formula = (cost_per ms) * (run_time ms)/(cadence per ms) * (call cadenence per day in seconds)
seconds_per_day) call cadence per second) * (minutes in hr) * (hrs in day) $0.0000000083 /ms * 30/0.5calls * 60ms/s * 60s/hr * 24hr/days

// basic calculation (cost per ms) * (run time ms)/(cadence per ms) * (call cadence per second) * (minutes in hr) * (hrs in day) $0.0000000083 /ms * 30/0.5calls * 60ms/s * 60s/hr * 24hr/days

= $0.14 per day

Secondly we have to factor in the cost charged per request. AWS charges $0.20 per million requests. Given the cadence of 2 request per second all day. Given our above assumptions on our product.

// basic calculation cost per call = (cost per million / 1 million) * (seconds in a day)(cadence per second) $0.03 = (0.2/1000000)*(86400)(2)

Combine these two together and we are looking at $0.17 USD per day which is $5.10 USD per month.

Given our constraints the pricing of the lambda service was not very expensive but it is important to note that these values can easily blow up if:

  1. The size of the AWS Function increases
  2. If the speed of the execution decreases
  3. If the cadence that the AWS function is hit increases

Keeping Connections Alive

Before a lambda instance goes to sleep (inactivity for more than 15 minutes) it keeps connections alive. For instance if a connection is made to a database, it will remember that connection after the first time the function is invoked and makes it (if that connection has been set globally).

Hopefully this helps with creating projections in the future!

--

--

Christien Kelly
Christien Kelly

Written by Christien Kelly

Just a guy learning new technologies.

No responses yet