Serverless Functions with AWS Lambda & API Gateway
Run code with no servers to manage. A Lambda behind an API Gateway, with the gotchas explained plainly.
In this guide
Serverless means you write a function and the cloud runs it — no VMs, no patching, and you pay only for the milliseconds it actually executes. For bursty workloads it's often the cheapest and simplest thing going.
A Lambda function
# lambda_function.py
import json
def lambda_handler(event, context):
# event carries the request; return a valid response
name = event.get("queryStringParameters", {}).get("name", "world")
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps({"message": f"hello {name}"}),
}The anatomy
- Trigger — what invokes it (API Gateway, S3 upload, a schedule).
- Handler — the function, receives an
eventdict. - Runtime — Python, Node, Go, Rust, whatever.
- Permissions — an IAM role granting exactly what it needs.
Deploy it
# package and upload (the long way, for understanding)
zip function.zip lambda_function.py
aws lambda create-function --function-name hello --runtime python3.12 --role arn:aws:iam::123456789012:role/lambda-basic --handler lambda_function.lambda_handler --zip-file fileb://function.zipThen attach an API Gateway trigger with a route GET /hello. In practice, a framework like AWS SAM, Serverless Framework or Terraform handles this wiring.
The gotchas
- Cold starts — first call after idle is slow (keep the function small; use provisioned concurrency if latency is critical).
- 15-minute max — long jobs need a queue or step functions.
- Stateless — persist to a database, not local disk.
- Timeouts — set them deliberately and handle them.
Lambda is brilliant for spiky work — webhooks, image processing, cron jobs. It's the wrong tool for steady, always-on traffic, which is cheaper on a small VPS.
Serverless removes a whole class of operational work. Understand its limits and it becomes a sharp tool, not a trap.
More from the lab
The OWASP Top 10: A Developer's Guide to Web Security
The ten most common web vulnerabilities, what each looks like in code, and how to fix them.
FrontendReact vs Vue vs Svelte: Choosing a Frontend Framework
A candid, no-hype comparison of React, Vue and Svelte — where each shines, and what to pick.
LinuxThe Linux Command Line for Developers: 30 Commands
The terminal commands that make you dramatically faster — navigation, files, pipes, processes.
Want us to build this for you?
We turn tutorials like these into production systems every day. Tell us what you need.
Start a project →