Skip to content

Instantly share code, notes, and snippets.

@ctulek
Created December 17, 2015 21:36
Show Gist options
  • Save ctulek/0e15f8d9a2faeb1e6235 to your computer and use it in GitHub Desktop.
Save ctulek/0e15f8d9a2faeb1e6235 to your computer and use it in GitHub Desktop.
AWS API Gateway Mapping Template to add all header, query, path, and stage parameters to JSON dynamically
{
"request": {
"context": {
"stage": "$context.stage"
},
"path": {
#foreach( $key in $input.params().path.keySet())
"$key": "$input.params().path.get($key)"#if( $velocityHasNext ),#end
#end
},
"headers": {
#foreach( $key in $input.params().header.keySet())
"$key": "$input.params().header.get($key)"#if( $velocityHasNext ),#end
#end
},
"query": {
#foreach( $key in $input.params().querystring.keySet())
"$key": "$input.params().querystring.get($key)"#if( $velocityHasNext ),#end
#end
},
"stage": {
#foreach( $key in $stageVariables.keySet())
"$key": "$stageVariables.get($key)"#if( $velocityHasNext ),#end
#end
},
"body": $input.json('$')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment