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?
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.
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error