Stop 10 · Cloud Platforms (AWS / GCP / Azure)Topics · 8/11

Serverless Basics (Lambda / Functions)

Part of the DevOps Roadmap

In short

What if you could run code without choosing, patching or paying for an idle server? Serverless functions run only when something triggers them, and you're billed for the time they actually run.

Running code in response to events without managing any servers directly — you pay only for actual execution time, and the platform handles all scaling automatically.

The mascot hands a crumpled shirt to a street-side ironing stall where a man presses it with a coal iron.

Think of it like this

The neighbourhood ironing stall

You don't buy an iron and a board for four shirts a week. You hand them to the istriwala at the corner, pay per piece, and he handles the coal, the board and the queue. Serverless is that stall: drop off a request, pay per run, no machine to look after.

Watch it happen

A request to a function

Phone app
Function URL
Function
Database

GET /hello?name=Riya

1/6The request hits an HTTPS endpoint managed by the cloud. No server of yours is listening.

The big ideas

What you need to know

Event-driven

Functions run on triggers: an HTTP call, a file landing in a bucket, a queue message or a schedule.

Pay per use

Billed by requests and run time. Ideal for spiky or low traffic, less so for constant heavy load.

Cold starts

The first call after idle is slower while a new copy starts. Keep packages small to shorten it.

Short and stateless

Functions have time limits and lose local memory between runs. Keep state in databases or storage.

See it in code

Walk through the code

js
1// index.mjs: runs only when a request arrives2export const handler = async (event) => {3  const name = event.queryStringParameters?.name ?? "friend";4 5  return {6    statusCode: 200,7    headers: { "content-type": "application/json" },8    body: JSON.stringify({ message: `Hello, ${name}!` }),9  };10};

1/3Lambda calls the exported handler with an event describing what triggered it.

This is an AWS Lambda handler for a Node.js runtime, called through a function URL or API Gateway. Azure Functions and Google Cloud Run functions look similar.

Save yourself the pain

Common mistakes

Oops

Opening a new database connection on every invocation of a busy function.

Do this instead

Create clients outside the handler so warm copies reuse them, and use a connection pooler or proxy for SQL databases.

Oops

Moving a long-running, always-busy service to functions to save money.

Do this instead

Constant heavy load is often cheaper on containers or VMs. Serverless shines for bursty, event-driven work.

Your mission

Your first function

~30 min

Quick check

Your function's first request after an hour takes 800 ms, later ones take 40 ms. What explains this?

Go deeper

  1. 1Deploy a simple function (AWS Lambda or equivalent) triggered by an HTTP request.
  2. 2Learn the trade-offs of serverless: no server management, but cold starts and execution time limits.
  3. 3Understand when serverless fits well (event-driven, spiky workloads) versus when it doesn't (long-running processes).

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge