I have an API Gateway, with the following mapping template:
application/x-www-form-urlencoded
#set($form=$input.path("$").split("&")) Action=SendMessage&MessageBody={#foreach($kvString in $form)#set($kv=$kvString.split("="))"$kv[0]": "$util.urlDecode($kv[1])"#if($foreach.hasNext),#end#end}&MessageGroupId=MGID
This will accept form submissions, and map them into an inline JSON string, which the API Gateway is configured to transmit to an SQS queue.
This will work with form submissions that have all field values completed, eg:
email=dummyemail%gmail.com&salutation=Mr&firstName=Dummy&lastName=Submission
But will not work with an example where a form submission has any fields without a value:
email=dummyemail%gmail.com&salutation=Mr&firstName=&lastName=Submission
This is not a form validation issue, it's failing at the point the API Gateway is using the mapping template to map to the format needed to transmit to SQS, with the error:
Execution failed due to configuration error: Unable to transform request
I have also tried URL encoding the output with the following template, but get the same issue:
#set($form=$input.path("$").split("&"))Action=SendMessage&MessageBody=$util.urlEncode("{")#foreach($kvString in $form)#set($kv=$kvString.split("="))$util.urlEncode("\"$kv[0]\":\"$util.urlDecode($kv[1])\"")#if($foreach.hasNext)$util.urlEncode(",")#end#end$util.urlEncode("}")&MessageGroupId=MGID
I have tried with a readable version of the template, but this also seems to fail with white space, so I'm really confused.
This is my first foray into this kind of configuration in API Gateways, and I'm not making much progress! Any help would be greatly appreciated