Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Created March 9, 2016 05:23
Show Gist options
  • Save pmuellr/126eb0404d2e98895d41 to your computer and use it in GitHub Desktop.
Save pmuellr/126eb0404d2e98895d41 to your computer and use it in GitHub Desktop.
aws api gateway integration request mapping template for aws lambda
{
"method": "$context.httpMethod",
"resourcePath": "$context.resourcePath",
"querystring": {
#foreach($key in $input.params().querystring.keySet())
"$key": "$input.params().querystring.get($key)"#if($foreach.hasNext),#end
#end
},
"path": {
#foreach($key in $input.params().path.keySet())
"$key": "$input.params().path.get($key)"#if($foreach.hasNext),#end
#end
},
"header": {
#foreach($key in $input.params().header.keySet())
"$key": "$input.params().header.get($key)"#if($foreach.hasNext),#end
#end
}
}
@pmuellr
Copy link
Author

pmuellr commented Mar 9, 2016

not quite json ...

This is an AWS API Gateway integration request mapping template for lambda that populates the lambda event with most of the http stuff you really want. Specifically, try it with a lambda function like:

exports.handler = function(event, context) {
    console.log('event', JSON.stringify(event, null, 4))

    context.succeed(event)
}

You can then curl that lambda, passing with something like

curl "https://{rando-chars-here}.execute-api.us-east-1.amazonaws.com/test/tester/g?x=4&y=5" | json

(assumes you set up test/tester/g as a resource)

and then see something like this:

{
  "method": "GET",
  "resourcePath": "/tester/{id}",
  "querystring": {
    "x": "4",
    "y": "5"
  },
  "path": {
    "id": "g"
  },
  "header": {
    "Accept": "*/*",
    "CloudFront-Forwarded-Proto": "https",
    "CloudFront-Is-Desktop-Viewer": "true",
    "CloudFront-Is-Mobile-Viewer": "false",
    "CloudFront-Is-SmartTV-Viewer": "false",
    "CloudFront-Is-Tablet-Viewer": "false",
    "CloudFront-Viewer-Country": "US",
    "Host": "{rando-chars-here}.execute-api.us-east-1.amazonaws.com",
    "User-Agent": "curl/7.43.0",
    "Via": "1.1 {rando-chars-here}.cloudfront.net (CloudFront)",
    "X-Amz-Cf-Id": "{rando-chars-here}==",
    "X-Forwarded-For": "{rando-ip-here}, {rando-ip-here}",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment