Skip to content

Instantly share code, notes, and snippets.

@avendasora
Created April 18, 2017 17:27
Show Gist options
  • Select an option

  • Save avendasora/41576de21c3b9b1617d982ee84ecdb1c to your computer and use it in GitHub Desktop.

Select an option

Save avendasora/41576de21c3b9b1617d982ee84ecdb1c to your computer and use it in GitHub Desktop.
AWS API Gateway body mapping template to convert simple JSON into DynamoDB JSON
#set($tableName = $input.params("tableName"))
#set($inputRoot = $input.path('$'))
{
"TableName": "$tableName",
"Item": {
"request_id": {
"S": "$context.requestId"
},
#foreach($key in $inputRoot.keySet())
#set($value = $inputRoot.get($key))
#set($class = $value.class)
##$class
#if($class == "class java.lang.Integer"
|| $class == "class java.lang.Double"
|| $class == "class java.lang.Float"
|| $class == "class java.lang.BigDecimal"
|| $class == "class java.lang.BigInteger"
)
#set($type = "N")
#elseif($class == "class java.lang.Boolean")
#set($type = "BOOL")
#else
#set($type = "S")
#end
"$key": {
"$type": "$value"
}#if($foreach.hasNext),#end
#end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment