Stop using AWS Lambda for everything!
Tags: serverless
Published: 2020-05-02 06:14:31

---
title: Stop using AWS Lambda for everything!
published: true
description: You probably don't need Lambda
tags: serverless
---

This is my reply to [a reddit *Explain Like I'm Five* thread](https://www.reddit.com/r/aws/comments/e5q4cw/eli5_aws_lambda_vs_ec2/fg2sdc7/) about Lambda vs. regular servers in the cloud (EC2, or VPSes).

---

There's another **MAJOR** con to Lambda: the warmup cost. It may take AWS a while (>5 seconds) to ["cold-start"](https://www.serverless.com/blog/keep-your-lambdas-warm/) your function if it wasn't recently running, which means you have unpredictable startup times, and unacceptably high startup times.

Imagine you're building an app in which users can create, modify, read and delete items. You build an API (GraphQL or REST) with functions like `createItem`, and run each on Lambda.

Imagine an API call to `createItem` when a user creates a new item in your app. Since this is not a frequent operation, the `createItem` function needs to be warmed up. So it takes 5 seconds for the Lambda function to actually process the request. And if there's a problem creating the item (invalid values or whatnot), the user will have to wait 5+ seconds until they get an error, or are sure the item creation succeeded.

**This is unacceptable.**

Unfortunately, Lambda is such a cargo-culted technology that junior devs use it for everything "because it's cool".

So they use it to run servers that should be up all the time and respond fast, e.g. API servers like the one I described. And because of the Lambda cold-start problem, they end up using... *[Lambda warmup plugins](https://www.npmjs.com/package/serverless-plugin-warmup)*! Which basically call all your Lambda functions all the time to "keep them warm".

**What's the point then?**

Why not run your API server on a real machine that,
* is always running so you have predictable response times
* responds in only the time required to actually process the API call (no 5-second "warm-up" cost)
* and costs you only [$5/mo](https://m.do.co/c/cc85b48ebd68)?

It's not that hard to install Node or PHP or whatever language you need, and to configure the system to automatic safety patches and upgrades. (These things literally take one command [each](https://unix.stackexchange.com/questions/107194/make-apt-get-update-and-upgrade-automate-and-unattended/107198#107198) on Linux, and the extra devops knowledge you'll learn by figuring these things out will be well worth it.)

AWS provides those too (they's called Lightsail), but the concept has been around for 20+ years. DigitalOcean and Linode are the best known providers of these "Virtual Private Servers", which are basically computers in the cloud you can access like any real computer. You can scale those too, with [load balancers](https://aws.amazon.com/lightsail/features/load-balancing/) or [EC2 Auto Scaling](https://aws.amazon.com/ec2/autoscaling/).

Good use cases for Lambda are long-running operations that happen unpredictably and don't need to respond quickly. [Netflix used it to transcode videos](https://dashbird.io/blog/serverless-case-study-netflix/).