What if your server only existed while someone was using it? That’s the idea behind AWS Lambda. In this post I explain what Lambda is, what happens when your code runs, why the first request is slower, how long a function can run now, and how you pay for it.

A hallway light with a motion sensor

A normal server is like a hallway light left on all night: you pay for every hour, even when nobody walks by. Lambda is the light with a motion sensor. It’s AWS’s serverless compute service: you upload your code and run it without provisioning or managing servers.

Functions, handlers and events

Your code is a function. Inside it, the handler is the method that runs when something happens. That something is an event: a request through API Gateway, a file landing in an S3 bucket, a message in an SQS queue, or one of more than 200 other AWS services.

The event arrives as a JSON document, and Lambda turns it into an object your code can use. In Python, a handler can be this small:

def lambda_handler(event, context):
    # event: the JSON that triggered this run, as a Python dict
    name = event.get("name", "world")
    return {"message": f"Hello, {name}"}

The light turns on, your handler runs, and the light turns off.

Cold starts and warm starts

The first time, the light flickers. That’s a cold start: Lambda downloads your code, starts the environment and runs any initialization code outside the handler. After that, AWS keeps the environment for a while, so the next request gets a warm start and skips the flicker.

That’s also why setup work, like creating a client for another service, usually goes outside the handler: it runs once when the environment starts, and warm requests reuse it.

What if a thousand people walk in at once?

Lambda switches on more lights. Each request running at the same time gets its own execution environment, so you never add servers yourself. There is a limit per account on how many can run at once (concurrency), and new accounts can start below the usual default of 1,000, so check yours before a big launch.

How long can one run last?

Since November 19, 2026, up to 30 minutes for on-demand functions, double the old 15-minute limit.

One catch: whatever waits for the answer keeps its own limit. API Gateway, for example, gives up after 29 seconds by default for REST APIs and 30 seconds for HTTP APIs. A long job behind an API should run in the background, not while the caller waits.

How you pay

You pay per request, plus how long your code runs, times the memory you gave it. Memory also sets the CPU: Lambda gives CPU in proportion to the memory you configure, so more memory buys more CPU too.

The free tier covers one million requests and 400,000 GB-seconds every month. I’m not quoting prices per request here: they change by Region and architecture, so check the pricing page for yours.

So, no servers?

Nope, there are plenty. You just never have to see one, set one up, or pay for one that sits idle all night.


Found it useful? Watch the short video on YouTube and subscribe to @Andrevops for more videos like this one.