7

I know how to access GET string variables in a Node js Lambda that is integrated with API Gateway with:

 event["queryStringParameters"]["variable_name"]

What is the equivalent for accessing POST variables?

1 Answer 1

18

Use the following

if (event.body !== null && event.body !== undefined) {
        let body = JSON.parse(event.body) //use in case of JSON body
        //your code
}

AWS Documentation

Sign up to request clarification or add additional context in comments.

7 Comments

I'm unsure why this answer was downvoted, but it is correct. When you receive a POST in your Lambda handler from API Gateway, the Lambda event contains a field called body which contains a JSON string representation of the POST body. You can parse the JSON into an object and access your POST variables as keys in the body object.
Thx. Json parse didn't work for me but the rest got me in the right track
@jaimerr you need to make sure your body is valid in json format
Your body will be whatever you post to it. If you post multipart form data, JSON parse will tank. That's probably why it is getting downvoted.
@PreetSaxena Above code example is for when the posted body is in JSON format. You can get an idea about multipart data here
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.