06 / 10

What is a Lambda function handler?

Difficulty: 4/10
handler signature, event source mapping, runtime execution

A Lambda function handler is the entry point for your AWS Lambda function. It's the method or function that AWS Lambda invokes when executing your code. The handler processes the input event and returns a response. Its structure and signature depend on the programming language runtime you're using.

Key Characteristics of a Lambda Handler
  1. 1

    Defined in the format fileName.functionName (e.g., index.handler)

  2. 2

    Receives two arguments: event (input data) and context (metadata)

  3. 3

    Must be exported or publicly accessible, depending on the language

  4. 4

    Should return a response or promise (async) in supported runtimes

  5. 5

    Handles any initialization or cleanup tasks inside the function body

Example of a Node.js Lambda Handler

Scenario Questions

0-2 years experience

  1. 1You need to write a Lambda that processes S3 put events. How would you name and structure the handler function, and what does AWS expect to call when the event arrives?
  2. 2If you accidentally export the handler as `processEvent` instead of `handler`, what will happen when the function is invoked?
  3. 3What are the two parameters that AWS passes to a Node.js Lambda handler, and what does each contain?

2-5 years experience

  1. 1Your Lambda is timing out after 30 seconds, and the logs show the handler never reached the end of its code. What could be wrong with the way the handler is defined or returns a promise?
  2. 2You added a DynamoDB stream as a new event source to an existing Lambda but the function isn’t being triggered. Walk me through how you’d verify the handler configuration and mapping.
  3. 3Explain why changing the handler signature from `(event, context)` to just `(event)` caused a runtime error in a Node.js Lambda.

5-8 years experience

  1. 1At scale you have dozens of Lambdas sharing a common utility library. How would you organize the handler code and deployment package to minimize cold‑start latency and keep versioning manageable?
  2. 2When migrating a monolithic service to Lambda, you need to decide whether each business capability gets its own handler or a shared handler with routing logic. What factors influence that decision?
  3. 3Describe how you’d instrument a handler to capture detailed metrics without impacting performance, and how you’d surface those metrics across teams.

8+ years experience

  1. 1Your organization wants to standardize Lambda handlers across many services to enforce logging, error handling, and tracing. How would you design a framework or base class that teams can adopt, and what trade‑offs does it introduce?
  2. 2During a multi‑region rollout you discover different teams have defined handlers with inconsistent signatures, causing deployment pipelines to break. How would you refactor the architecture to enforce a contract while supporting backward compatibility?
  3. 3If you need to support both synchronous API Gateway invocations and asynchronous SQS events with the same Lambda codebase, how would you structure the handler to cleanly separate concerns while keeping the deployment unit simple?

Follow-up Questions

  • What does the context object provide to the handler?
  • How does AWS know which function to call when the Lambda is invoked?
  • What happens if the handler throws an uncaught exception?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.