Mapping Template Example for AWS API Gateway
The following mapping template should provide most all of the relevant data you'd be interested in from an HTTP request perspective:
#set($headers = $input.params().header)
{
"method": "$context.httpMethod",
"resourcePath": "$context.resourcePath",
"queryString": "$input.params().querystring",
"requestBody": "$input.json('$')",
"stage": "$context.stage",
"headers": [
#foreach($key in $headers.keySet())
{
"key": "$key",
"value": "$util.escapeJavaScript($input.params().header.get($key))"
}
#if($foreach.hasNext),
#end
#end
],
"userAgent": "$context.identity.userAgent"
}
{
"method": "GET",
"resourcePath": "/",
"queryString": "{}",
"requestBody": "{}",
"stage": "test",
"headers": [
{
"key": "Accept",
"value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
},
{
"key": "Accept-Encoding",
"value": "gzip"
},
{
"key": "Accept-Language",
"value": "en-US,en;q=0.8"
},
{
"key": "CloudFront-Forwarded-Proto",
"value": "https"
},
{
"key": "CloudFront-Is-Desktop-Viewer",
"value": "true"
},
{
"key": "CloudFront-Is-Mobile-Viewer",
"value": "false"
},
{
"key": "CloudFront-Is-SmartTV-Viewer",
"value": "false"
},
{
"key": "CloudFront-Is-Tablet-Viewer",
"value": "false"
},
{
"key": "CloudFront-Viewer-Country",
"value": "US"
},
{
"key": "Upgrade-Insecure-Requests",
"value": "1"
},
{
"key": "Via",
"value": "1.1 e66d582bff32cb7f7478c73177a985e9.cloudfront.net (CloudFront)"
},
{
"key": "X-Amz-Cf-Id",
"value": "xQAFSfjvzbfHq4-KmVCpIBJfYjF46L2E4Gb9HYWBoCDtLqHI4vmh_w=="
},
{
"key": "X-Forwarded-For",
"value": "108.183.183.220, 216.137.44.11"
},
{
"key": "X-Forwarded-Port",
"value": "443"
},
{
"key": "X-Forwarded-Proto",
"value": "https"
}
],
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"
}
Check out the docs for more info on how to get the most out of mapping templates.