How to convert application/x-www-form-urlencoded data coming via POST
request into API gateway into a JSON
object so you may send said object to Step Functions
without first sending to Lambda for pre-processing.
(Answer included below)
application/x-www-form-urlencoded
StartExecution/StartSyncExecution
Mapping Template:
#set($data = "")
#foreach( $token in $input.path('$').split('&') )
#set( $keyVal = $token.split('=') )
#set( $keyValSize = $keyVal.size() )
#if( $keyValSize >= 1 )
#set( $key = $util.urlDecode($keyVal[0]) )
#if( $keyValSize >= 2 )
#set( $val = $util.urlDecode($keyVal[1]) )
#else
#set( $val = '' )
#end
#end
#set($data =
"${data}\""${key}\"":\""$util.escapeJavaScript($val)\""#if($foreach.hasNext),#end")
#end
{
"input": "{$data}",
"stateMachineArn": "YOUR STEP FUNCTION ARN"
}
Given your role has proper permissions, this mapping template will result in your step function executing properly with a beautifully formatted JSON
object inputted.