app.js file code :
app.post('/update/name', function(req, res){
console.log('Request came : ', req) // I printed the whole request no body came
}
lambda.js (this is the handler function)
'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const binaryMimeTypes = [
'application/javascript',
'application/json',
'application/octet-stream',
'application/xml',
'font/eot',
'font/opentype',
'font/otf',
'image/jpeg',
'image/png',
'image/svg+xml',
'text/comma-separated-values',
'text/css',
'text/html',
'text/javascript',
'text/plain',
'text/text',
'text/xml'
]
const server = awsServerlessExpress.createServer(app, null,
binaryMimeTypes)
exports.handler = (event, context) => {
console.log('body came from api gateway', event.body) // here we can see the body in cloudwatch logs
awsServerlessExpress.proxy(server, event, context) // but when this method makes request to our app.js file where the request goes, no body comes there.
}
aws-serverless-express (built in node module) code :
consider this link for the code :
https://github.com/awslabs/aws-serverless-express/blob/master/index.js
In the aws-serverless-code, I commented this line : https://github.com/awslabs/aws-serverless-express/blob/master/index.js#L36 then I was able to get the body in headers['x-apigateway-event'] that I was reading in app.js, but this is not the correct way as I am touching the modules and when I commit the code in github without node modules, then if another member of my team will pull the code, then he will again not get the body.