serverless-express
serverless-express copied to clipboard
Request body is empty - awsServerlessExpress.proxy eats up event body
I have tried everything - I have set headers to application json, I have used body parser - nothing works.
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
exports.handler = (event, context) => {
console.log(event); // Has event body
awsServerlessExpress.proxy(server, event, context); // Does not have event body
};
Why is this eating up event.body? This is an issue that has plagued this library for so long and there are posts about it every week. Can someone please offer some guidance here? I may have to switch libraries and potentially stop using Claudiajs just because of this issue.
@ethoman I had the same problem when I run the lambda local with a event.json.
In my case, I had to add the following header: Content-Type: application/json to let express (and body-parser bodyParser.json()) parse the body.
{
"httpMethod": "POST",
"path": "/my-url",
"body": "{"email\": \"[email protected]\"}",
"headers": {
"Content-Type": "application/json"
}
}
Thanks @kaldebert. @ethoman does this solve your issue?