Get non-file body from multipart / form-data using AWS API Gateway and Lambda

I am trying to get form data from multipart/form-data POST to my ASW Lambda web service through an API gateway.

HTTP POST has a Content-Type of "multipart / form-data" and a URL encoded body. File data is also sent in this message (therefore, this is a multi-user option).

The web service must integrate with the thirdparty service, so changing the POST format is not really an option.

I saw this thread talking about converting URL encoded data to a JSON object for use in Lambda, but this does not do the trick.

I also tried setting Integration Request -> Mapping Templates for the content type multipart/form-data to enter PASSTHORE. It didnโ€™t help either.

I came across another question about uploading a file using multipart/form-data , but since I am not interested in the file, just the body, this answer didn Help.

Below is a screenshot (sorry) for the captured message via runscope.

Message Details

+7
forms amazon-web-services aws-lambda aws-api-gateway
source share
1 answer

If the goal is to use Lambda, you need to pass a valid JSON to the function. There is currently no JSON-ify data inside Api Gateway that arrives as data other than JSON.

Our short fix (in our lag) is to provide a variable in the matching patterns to capture the raw request input. This way you can do a simple JSON conversion using a template, for example:

 { "body" : "$input.body" } 

or something like that.

Check out the mapping template link for more information: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

Edit 4/7 - The function was released as $ input.body

+4
source share

All Articles