Ad

How To Know That In Lambda,when To Use Event And Event.body

I am new on writing lambda using nodejs. I need to write an API to let user login and send back an access token.

So I study others example and I found that sometimes when I write a post method the body (e.g. {'username':'***' , 'password' : '***'}) can be accessed let say

exports.handler = async event => { console.log(event.body) }

and sometimes can only be called by

exports.handler = async event => { console.log(event) }

I have tried to use postman to check the difference between their codes and my code. Even if I copy the example I can only access the body in the event but not event.body. Can anyone explain me why there is this difference?

Ad

Answer

This is one of the differences between Lambda Proxy Integration and the Lambda Non-Proxy Integration.

With the first one you always get body as a string in event body.event.

Whereas with the Non-Proxy integration you can specify how does the request from client map to event using Mapping Tempaltes.

Ad
source: stackoverflow.com
Ad