Course outline · 0% complete

0/27 lessons0%

Course overview →

Functions instead of servers

lesson 7-1 · ~9 min · 19/27

Quiz

Warm-up from lesson 3-1: with EC2, what are you billed for while your app waits idle for the next request at 4 a.m.?

Lambda

Lambda is AWS's serverless compute service. Servers still exist (everything runs on the machines from unit 1), but they stop being your concern: no instance, no SSH, no patching, no security group to babysit for the compute itself.

The unit of deployment shrinks from a machine to a function: one piece of code with an entry point called a handler. You upload the code (a zip, or a container image, familiar territory), and AWS runs one copy of it per event, billing you per invocation and per millisecond of runtime. A handler receives an event, a JSON description of whatever happened, does its work, and returns.

Zero traffic costs zero dollars. A thousand simultaneous events means AWS spins up as many copies as needed. That is elasticity from lesson 1-3 taken to its limit, and it is why serverless fits spiky and occasional workloads so well.

Code exercise · bash

A Lambda handler in miniature: a script that wakes up, reads its event from stdin, does its job, and exits. Run it. The stdin box is preloaded with the event "user.signup".

Code exercise · bash

Your turn. Write a handler for a greeting API: read the name from stdin (preloaded with "Ada") and print an HTTP-style response exactly like the expected output, statusCode 200 and a body greeting the name. Mind the quotes.