Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Payloads

I searched on AWS Lambda documentation but couldn't find an answer to my problem.

Is there a way I can access the entire request body from a Lambda function (written in node.js)?

The event parameter only seems to contain parsed JSON properties.

like image 619
E. Lovelace Avatar asked Aug 17 '15 09:08

E. Lovelace


2 Answers

Your request body needs to be in XML or JSON in order to be able to access it in your Lambda function. You need to specify how it's processed/mapped and passed through in Integration Request section of the API Gateway dashboard.

like image 193
adamkonrad Avatar answered Oct 05 '22 17:10

adamkonrad


You can access the request body in AWS Lambda once you expose it in a Body Mapping Template.

  1. Open up your method in API Gateway console
  2. Open Integration Request
  3. In Integration Request, open the Body Mapping Templates panel
  4. Add a Content Type of application/json
  5. Click on your freshly created application/json item
  6. Add the following template:
 {
   "body" : $input.json('$')
 }

After that you can access the request body as event.body in your Node.js Lambda Function.

like image 44
David Salamon Avatar answered Oct 05 '22 16:10

David Salamon