Skip to content

How to understand a AWS Lambda (Serverless and SAM) codebase

A Lambda codebase is a set of handler functions, each triggered by an event source such as API Gateway, SQS, S3 or a schedule. The handlers are only half the picture; the deployment config (Serverless, SAM or CDK) decides which event calls which function.

How to tell it's AWS Lambda (Serverless and SAM)

  • serverless.yml, template.yaml (SAM) or a CDK app
  • Exports like export const handler = async (event, context) => {}
  • @types/aws-lambda and AWS SDK v3 clients such as @aws-sdk/client-dynamodb

Where things usually live

serverless.yml or template.yaml
Functions, triggers, permissions and environment variables.
src/handlers/ or functions/
One handler per file or per function.
src/lib/
Shared code: database clients, validation, logging.
layers/
Shared dependencies deployed as Lambda layers.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. The deployment config, to map triggers to handlers
  2. The handler for the trigger you care about
  3. Shared clients created outside the handler

How a request moves through the code

  1. 1An event source (HTTP request, queue message, file upload, schedule) triggers the function.
  2. 2Code outside the handler runs once per cold start, often creating clients.
  3. 3The handler receives the event shape for that trigger and the context.
  4. 4It calls AWS services through the SDK with permissions from its IAM role.
  5. 5It returns a response (for HTTP) or throws, which may trigger retries for async sources.

Questions to ask about the repository

  • Which trigger invokes each handler?
  • Which handlers can be retried, and are they idempotent?
  • What IAM permissions does each function have?

What trips people up

  • The wiring lives in YAML or infrastructure code, so a handler can look unused when it's called by a trigger.
  • API Gateway v1 and v2 events have different shapes; check which one a handler expects.
  • Async triggers retry on failure, so a bug can run the same side effect several times.