Stop 08 · Serverless & Event-Driven ArchitectureTopics · 2/9

Functions as a Service (Lambda, Cloud Functions)

Part of the Cloud Computing Roadmap

In short

A function is the smallest thing you can deploy to the cloud: one handler, a few lines, triggered by an event. Learn its shape once and use it on AWS, Google Cloud or Azure.

The core serverless compute primitive — a function that runs in response to a trigger (an HTTP request, a file upload, a schedule) and scales automatically to handle any volume of concurrent invocations.

The blob character presses a button on a chai vending machine as a cup fills.

Think of it like this

The office chai machine

Press the button, the machine wakes up, makes one cup and goes idle. Ten people press at once? A bigger office would have ten machines. It does one small job per press and never sits there brewing for nobody.

Watch it happen

One request through a function

Browser
API Gateway
Lambda

GET /hello?name=Riya

1/5The browser calls a public URL. The gateway owns that URL, not your code.

The big ideas

What you need to know

Handler shape

Every FaaS platform gives your function an event (what happened) and context, and expects a result back.

Many triggers

HTTP, storage uploads, queue messages, database changes and cron schedules can all invoke a function.

Stateless

Don't keep data in memory or local disk between calls. Store it in a database or object storage.

Same idea, three clouds

AWS Lambda, Google Cloud Run functions and Azure Functions differ in limits and tooling, not in the basic model.

See it in code

Walk through the code

js
1export const handler = async (event) => {2  const name = event.queryStringParameters?.name ?? "friend";3 4  if (name.length > 40) {5    return { statusCode: 400, body: "Name too long" };6  }7 8  return {9    statusCode: 200,10    headers: { "content-type": "application/json" },11    body: JSON.stringify({ message: `Hello, ${name}` }),12  };13};

1/4Lambda calls this exported async function once per event.

A Node.js Lambda handler for an HTTP API. The body must be a string, so objects go through JSON.stringify.

Save yourself the pain

Common mistakes

Oops

Writing a temp file in one invocation and expecting it in the next.

Do this instead

Each call may land on a different copy. Use S3 or a database for anything you need later.

Oops

Putting a whole Express app with 300 routes into one giant function.

Do this instead

Fine for small apps, but large ones get slow starts and messy permissions. Split by area when it grows.

Your mission

Write and break a function

~30 min

Quick check

Why should a Lambda function avoid storing user sessions in a global variable?

Go deeper

  1. 1Deploy a simple function triggered by an HTTP request and test it end to end.
  2. 2Learn the basic execution model: trigger, invocation, execution, response.
  3. 3Practice setting a function's memory and timeout configuration appropriately for its workload.

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