When trying to set up an endpoint that receives data as application/x-www-form-urlencoded
and starts executing a Step Function, the best mapping template I could come up with was:
#set($body = {
"context": {
"proxy": {
"source_ip": "$context.identity.sourceIp",
"http_method": "$context.httpMethod",
"request_id": "$context.requestId",
"url": "$context.domainName"
}
},
"payload": {
#foreach($token in $input.path('$').split('&'))
#set($keyVal = $token.split('='))
#set($key = $util.urlDecode($keyVal[0]))
#set($val = $util.urlDecode($keyVal[1]))
"$key": "$val"#if($foreach.hasNext),#end
#end
}
})
{
"input": "$util.escapeJavaScript($body)",
"stateMachineArn": "arn:aws:states:us-east-1:12345:stateMachine:name"
}
This seems to be the right approach, based on what I've researched, but it keeps failing to transform:
Execution failed due to configuration error: Unable to transform request
I've been playing with the mapping template for a few hours now, and I'm not sure what could be the problem. Without debugging tools, it's hard to pinpoint exactly what might be going wrong, although I did deploy multiple times, with different pieces of the template shared above.
It seems that there are two bugs:
- Looping through the body of the request in a variable (similar code can be found here).
- Trying to escape the body object. AWS's VTL documentation is lacking, and I'm not sure what I'm doing wrong here.
I'd appreciate any assistance, more specifically to help me figure out what exactly is breaking the transformation.