by

Sending all HTTP parameters in API Gateway

Here’s an API Gateway mapping template to send all HTTP path, query string, and header parameters to your backend integration (i.e. Lambda function).

#set($allParams = $input.params())
{
    "body-json" : "$input.json('$')",
    "params" : {
    #foreach($type in $allParams.keySet())
        #set($params = $allParams.get($type))
        "$type" : {
            #foreach($paramName in $params.keySet())
                "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
                #if($foreach.hasNext),#end
            #end
        }
        #if($foreach.hasNext),#end
    #end
    }
}

will produce something like:

{
   "body-json":"{}",
   "params":{
      "path":{
         "pathParamName1":"pathParamValue1",
         "pathParamName2":"pathParamValue2",
         "pathParamName3":"pathParamValue3"
      },
      "querystring":{
         "queryParamName1":"queryParamValue1",
         "queryParamName2":"queryParamValue2",
         "queryParamName3":"queryParamValue3"
      },
      "header":{
         "headerParamName1":"headerParamValue1",
         "headerParamName2":"headerParamValue2",
         "headerParamName3":"headerParamValue3"
      }
   }
}

The parameters can then be accessed in your Lambda function, i.e.

exports.myHandler = function(event, context) {
   console.log("pathParamName1 = " + event.params.path.pathParamName1);
   context.succeed("");
}

Here’s a Gist with the example.

Cheers,
Ryan

Leave a Reply for Patrick C Cancel Reply

Write a Comment

Comment

  1. That wouldn’t work currently as non-alpha characters aren’t supported in parameter names in API Gateway. I’ve seen many conventions for query string arrays/maps but there’s no accepted standard defined in RFC3986, so API Gateway typically doesn’t support these. I’d recommend following up on the API Gateway forums with your specific use case.

    Cheers,
    Ryan

Webmentions

  • tadalafil 20 mg canadian drug stores January 6, 2016

    tadalafil 20mg

    cialis tadalafil reviews add.asp – cialis pills online reply #4 on – cialis 10mg price announcements

  • generic viagra January 6, 2016

    viagra for sale

    viagra bivirkninger – viagra commercials settings – viagra risks

  • viagra 100mg January 6, 2016

    viagra for sale

    viagra for women does it work jump to – trackback skriv en kommentar viagra – viagra dose medications contact info

  • walmart cialis January 6, 2016

    cialis at walmart

    brand cialis – cialis commercial last post – cialis dosage forum newbie

  • levitra coupon January 6, 2016

    levitra vs viagra

    natural remedies for ed – dosage for levitra – levitra 5 mg