How to pass a params from POST to AWS Lambda from Amazon API Gateway
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When API Gateway triggers a Lambda function from an HTTP POST, the data does not arrive as ordinary function arguments. It arrives inside the Lambda event object. The easiest and most common setup is Lambda proxy integration, where API Gateway forwards the request body, headers, query string parameters, and path parameters in a standard event shape.
The Simplest Model: JSON Body in a POST
Suppose the client sends this request:
With proxy integration enabled, Lambda receives an event that includes a body field containing the raw JSON string.
A Python Lambda handler might look like this:
The important point is that the POST parameters are inside event["body"], not passed directly as top-level Python arguments.
What the Event Usually Contains
With Lambda proxy integration, API Gateway typically sends fields such as:
- '
body' - '
headers' - '
queryStringParameters' - '
pathParameters' - '
httpMethod' - '
isBase64Encoded'
That means a single request can carry data in several places.
For example:
This is useful when your endpoint mixes a JSON body with route parameters or query filters.
Path Parameters and Query Parameters
If the route is something like /users/{id} and the caller also sends ?verbose=true, the Lambda event usually contains:
- '
event["pathParameters"]["id"]' - '
event["queryStringParameters"]["verbose"]'
Example:
This is separate from the JSON POST body. API Gateway keeps these sources distinct.
If You Use Form-Encoded POST Data
Not every POST request is JSON. A client may send form data such as:
In that case, the body still arrives as a string, but you parse it differently:
So the transport format matters. JSON and form encoding are parsed differently even though both arrive through POST.
Non-Proxy Integration Works Differently
If you are not using Lambda proxy integration, API Gateway can transform the request before Lambda sees it. In that case, you define a mapping template and decide exactly what shape Lambda receives.
For example, a mapping template might build a custom JSON object that pulls from body and query fields. That approach is still valid, but it is more work and usually unnecessary unless you need strict transformation or backward compatibility.
For new serverless APIs, proxy integration is usually the simpler starting point because the event shape is predictable and the Lambda code does the parsing.
Common Pitfalls
The biggest pitfall is expecting POST fields to appear as normal Lambda function parameters. They do not. You always read them from the event.
Another common issue is forgetting to json.loads(event["body"]) when the client sends JSON. The body arrives as a string, not as a parsed Python dictionary.
People also often confuse body parameters with query parameters. In API Gateway they are separate parts of the event, and your code needs to read the right one.
Finally, watch for None values. queryStringParameters and pathParameters may be missing entirely, so defaulting to an empty dictionary makes the handler more robust.
Summary
- With API Gateway and Lambda proxy integration,
POSTdata arrives inside the Lambda event. - JSON
POSTbodies usually live inevent["body"]and must be parsed. - Query parameters and path parameters are separate from the body.
- Form-encoded requests need different parsing than JSON requests.
- Proxy integration is usually the simplest setup unless you specifically need custom mapping templates.
Related reading
- How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway
- How to pass an empty string as value of a field in dynamodb?
- how to pass an object to amazon SNS
- How to pass input parameter to AWS Glue Map.apply function
- How to pass body into aiohttp get request?
- How to populate select options from an Api call in React js on page load
- How to pass Kinesis Firehose data to dynamodb table?
- How to pg_dump an RDS Postgres database?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.