8

I am trying to get the form data from a multipart/form-data POST to my ASW Lambda web service via API Gateway.

The HTTP POST has Content-Type "multipart/form-data" and body that is URL encoded. File data is also sent in this post (hence the multipart, I guess).

The web service needs to integrate with a thirdparty service, so changing the format of the POST isn't really an option.

I have seen this thread talking about converting the URL encoded data to JSON object for use in Lambda, but this doesn't do the trick.

I have also tried setting the Integration Request -> Mapping Templates for content type multipart/form-data to Input passthrough. This didn't help either.

I did come across another question about uploading a file using multipart/form-data, but since I'm not interested in the file, just the body, that answer didn't help.

Below find screenshot (sorry) of the captured post via runscope.

Post details

2
  • Can you show an example of the post body? Commented Nov 30, 2015 at 17:00
  • @Ryan updated with screenshot of post. Commented Nov 30, 2015 at 18:42

1 Answer 1

5

If the goal is to use Lambda, you'll need to pass valid JSON to the function. Currently there isn't a way to JSON-ify data inside Api Gateway that comes in as non-JSON data.

Our short term fix (on our backlog) is to provide a variable in the mapping templates to grab the raw input of the request. That way you could do a simple JSON conversion using a template like:

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

or something like that.

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

Edit 4/7 - feature has been released as $input.body

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the answer. I suspected that it was a JSON only service. (Not too unreasonable given the direction most Web APIs are heading.) I worked around this restriction by putting another service in between, that does the translation.
Hi @Jack is this $input.raw variable available yet?
Not yet, we're still working on getting through a lot of other items on the backlog. No ETA at this point, unfortunately. My apologies!
Hey @JackKohn-AWS, I think without this feature there's no way to use signatures to verify incoming requests from webhooks like Github - developer.github.com/webhooks/securing . This is a pretty limiting feature for us. Any updated ETA on this?
To answer my own question above, AWS has added a mapping called "$input.body", see - forums.aws.amazon.com/thread.jspa?threadID=228067
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.