Python
Lambda Function
Callback
AWS Lambda
Programming

I can't find callback parameter in python lambda handler

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Python AWS Lambda handlers do not use a callback parameter like older Node.js Lambda examples. In Python, the runtime calls your handler with only event and context, and success or failure is represented by your return value or by an exception.

Use the Correct Python Handler Signature

The standard Python Lambda handler signature is:

python
def handler(event, context):
    ...

There is no third callback argument. If you define handler(event, context, callback), the Lambda runtime will not invoke it correctly.

This is the root of the confusion for many developers who have copied patterns from Node.js tutorials.

Return Values Replace Callback Success

In callback-driven runtimes, success is often signaled by calling the callback with a result. In Python, you simply return the result.

python
1import json
2
3
4def handler(event, context):
5    name = event.get("name", "world")
6    return {
7        "statusCode": 200,
8        "headers": {"Content-Type": "application/json"},
9        "body": json.dumps({"message": f"hello {name}"}),
10    }

If the function is behind API Gateway or a Function URL, that dictionary becomes the HTTP-style response.

Raise Exceptions or Map Errors Explicitly

Failures are represented by raised exceptions or by explicit error responses, depending on the event source and the style you want.

python
1import json
2
3
4def handler(event, context):
5    try:
6        quantity = int(event.get("quantity", 0))
7        if quantity <= 0:
8            raise ValueError("quantity must be positive")
9
10        return {
11            "statusCode": 200,
12            "body": json.dumps({"accepted": quantity}),
13        }
14    except ValueError as exc:
15        return {
16            "statusCode": 400,
17            "body": json.dumps({"error": str(exc)}),
18        }

That is the Python replacement for “call callback with an error.”

Why Tutorials Mention Callback at All

Older AWS Lambda examples for Node.js often showed a callback parameter. That pattern belongs to the Node.js runtime model, not the Python runtime model.

A useful mental separation is:

  • older Node.js examples often used callback
  • Python uses return and raise

Once you keep those runtimes separate, the missing callback stops being mysterious.

Async Workflows Use AWS Services, Not a Callback Parameter

If what you really want is deferred or asynchronous behavior, the answer is not a Python callback argument. The answer is usually an AWS async pattern such as:

  • asynchronous Lambda invocation
  • SQS or SNS fan-out
  • EventBridge routing
  • Step Functions orchestration
python
1import boto3
2import json
3
4lambda_client = boto3.client("lambda")
5
6
7def handler(event, context):
8    payload = {"job_id": event.get("job_id")}
9    lambda_client.invoke(
10        FunctionName="worker-function",
11        InvocationType="Event",
12        Payload=json.dumps(payload).encode("utf-8"),
13    )
14    return {"statusCode": 202, "body": json.dumps({"status": "queued"})}

That gives you callback-like architecture behavior without changing the handler signature.

Match the Return Shape to the Trigger Type

Not every Lambda trigger expects an API Gateway-style dictionary. SQS, EventBridge, and many other event sources ignore statusCode and body completely. The correct return format depends on the trigger.

So the real rule is:

  • Python handlers always accept event and context
  • the returned payload shape depends on the invoking service

That distinction matters more than the absence of a callback.

Common Pitfalls

  • Defining a Python Lambda handler with a third callback parameter.
  • Copying Node.js Lambda examples into Python without changing the execution model.
  • Returning API Gateway-style responses for triggers that do not care about them.
  • Treating asynchronous workflow design as if it should come from a handler callback.
  • Using broad exception handling without clear error mapping for the real caller.

Summary

  • Python Lambda handlers take only event and context.
  • Success is represented by a return value, not by invoking a callback.
  • Failures are represented by exceptions or explicit error responses.
  • Callback-based examples usually come from older Node.js Lambda patterns.
  • For deferred workflows, use AWS async services rather than trying to add a Python callback parameter.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.