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.

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

python
# 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 event dict.
  • Runtime — Python, Node, Go, Rust, whatever.
  • Permissions — an IAM role granting exactly what it needs.

Deploy it

bash
# 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.zip

Then 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.

Your move

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 →