
AWS Lambda is the most well-known serverless product on the market. The way it works is it lets you publish code as a Lambda function that gets triggered by some event (e.g. an object appears in an S3 bucket).
AWS Lambda charges you based on what you use. This can be nice for running bursty, unpredictable workloads especially compared to using EC2 where you may be over / under-provisioned at any given moment.
How AWS Lambda pricing works
AWS Lambda charges per GB per second of compute time plus number of requests.
Cost | Free per month | |
---|---|---|
Compute time | $0.0000166667 / GB-s | 400,000 GB-s |
Requests | $0.20 per 1M requests | 1 million requests |
Compute Time
AWS Lambda pricing starts at $0.0000166667 per GB per second of runtime (GB-s). This assumes an x86 instance running in us-east-1.
This base rate card decreases as compute goes up. For example, if you exceed 6 billion GB-seconds per month, successive compute gets billed at $0.000015 per GB-second.
Your first 400,000 GB-s per month are free.
Requests
On top of compute time, AWS Lambda also charges $0.20 per 1 million requests. Your first 1 million requests are free.
Additional charges
There are other charges you may incur, including ephemeral storage, provisioned concurrency, and data transfer across regions / clouds.
Example
Let’s say you have a Lambda function that process JSON data in a file and gets triggered every time a file appears in an S3 bucket:
- Number of requests per month: 2M
- Average compute time per job: 1 second
- 10GB memory required
Compute seconds = 2M * 1 second = 2M
GB-seconds = 2M compute seconds * 10 GB = 20M
Compute cost = (20M - 400,000) * $0.0000166667 = $326.67
Request cost = (2M - 1M) * $0.20 = $0.20
Total cost = $326.87 per month
Comparison with Modal
Modal charges for CPU cores and memory separately as opposed to a single GB-second $ rate. If we know that a 1.8 GB Lambda function is equal to one vCPU, then we can infer the above example to use 5.6 vCPUs = 2.8 physical CPU cores on Modal.
So the cost of the above example on Modal would look like:
- CPU cost: 2.8 * $0.0000131 * 2M compute seconds = $73.36
- Memory cost: 10GB * $0.00000222 * 2M = $44.4
- Total cost = $117.76 - $30 free credits = $87.76 per month
Moving the workload above to Modal from Lambda would reduce your cost by 73%. On top of that, Modal does not charge for number of requests or storage.
Conclusion
AWS Lambda charges per GB per second of compute time plus number of requests.
While AWS Lambda is the de-facto incumbent in the serverless space, its pricing model is unnecessarily complicated and you can probably find better rates on pure serverless providers like Modal.