How do I get raw body in my Lambda?


I’m trying to use signature on my Stripe webhooks. In Stripe’s docs they’re using body-parser with Express (bodyParser.raw({type: 'application/json'})). I searched for the issue and best to my research (github issue I can do it in Lamda provided I pass raw body along with the signature and my secret.

As described in the GitHub issue, I need to map the endpoint from AWS admin console. From there, there is a way to set up Body Mapping Template and include rawbody": "$util.escapeJavaScript($input.body)", which will then let me use rawbody in my Lambda.

How can I create a mapping like this with Netlify, or is there an alternative to get raw body? I understand it needs to be exactly the way Stripe sent it to my endpoint, passed back on to Stripe.


Hi @abtx, It’s not possible to add any custom configuration to your function since it’s not deployed to your AWS account. I have not looked in to this before but just to clarify, have you tried using the event.body string?

Hi @futuregerald , yes, I did. Stripe API requires raw body specifically. Is there any way Netlify will enable it or has plans for AWS like config in the functions?

@abtx, there aren’t any plans to allow passing the raw body into functions, but it is possible to use your own aws lambda account if you have a custom netlify plan, but even with this, I don’t know if the raw body will be sent properly since we do use our own proxy between the request and the lambda function. This is likely a use-case that you can’t do with Netlify in the near future. Sorry about that!

That’s a shame. I hope I can find another way to verify webhooks then, but probably not as secure. Thanks for the reply.