Skip to content

Instantly share code, notes, and snippets.

@avendasora
avendasora / form-to-dynamodb-json.template
Last active September 20, 2022 05:00
AWS API Gateway body mapping template to convert "application/x-www-form-urlencoded" into "application/json" for DynamoDB
#set ($keyValues = {})
#set($prarametersString = $input.body)
#set($parameters = $prarametersString.split("&"))
#foreach($parameter in $parameters)
#set($keyValue = $parameter.split("="))
$keyValues.put($util.urlDecode($keyValue[0]),$util.urlDecode($keyValue[1]))
#end
{
"TableName": "table_name",
"Item": {
@ryanray
ryanray / aws-api-gateway-form-to-json.ftl
Created October 4, 2015 01:24
API Gateway application/www-form-urlencoded to application/json based on https://forums.aws.amazon.com/thread.jspa?messageID=673012&tstart=0#673012
## convert HTML POST data or HTTP GET query string to JSON
## get the raw post data from the AWS built-in variable and give it a nicer name
#if ($context.httpMethod == "POST")
#set($rawAPIData = $input.path('$'))
#elseif ($context.httpMethod == "GET")
#set($rawAPIData = $input.params().querystring)
#set($rawAPIData = $rawAPIData.toString())
#set($rawAPIDataLength = $rawAPIData.length() - 1)
#set($rawAPIData = $rawAPIData.substring(1, $rawAPIDataLength))