by

An API Gateway mapping template to “send everything” to your Lambda function

If you’re trying to get up to speed with developing microservices on API Gateway and Lambda, one of the first things you will want to try is to send basic API request data to your Lambda function.

Since all Lambda function input data must go in the request body, you must use an API Gateway mapping template to build a JSON representation of your data.

Here’s a master template to “send everything” API Gateway provides (as of 02/22/2016) to your Lambda function. This should serve as a good starting point and can be modified to suit your use-case. This will include all HTTP parameters, context data, stage variables, and the full method request body.

## API Gateway "Send Everything" Mapping Template - Ryan Green - ryang@ryang.ca
##  See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
#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
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
    #if($foreach.hasNext),#end
#end
},
"context" : {
    "account-id" : "$context.identity.accountId",
    "api-id" : "$context.apiId",
    "api-key" : "$context.identity.apiKey",
    "authorizer-principal-id" : "$context.authorizer.princialId",
    "caller" : "$context.identity.caller",
    "cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
    "cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
    "cognito-identity-id" : "$context.identity.cognitoIdentityId",
    "cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
    "http-method" : "$context.httpMethod",
    "stage" : "$context.stage",
    "source-ip" : "$context.identity.sourceIp",
    "user" : "$context.identity.user",
    "user-agent" : "$context.identity.userAgent",
    "user-arn" : "$context.identity.userArn",
    "request-id" : "$context.requestId",
    "resource-id" : "$context.resourceId",
    "resource-path" : "$context.resourcePath"
    }
}

Here’s a Gist with the code.

For more information, check out the API Gateway mapping template reference.

Cheers,

Ryan

Write a Comment

Comment

Webmentions

  • 10 mg tadalafil generic February 23, 2016

    buy cialis generic tadalafil

    best price for tadalafil 20 mg

  • ivermectin 12mg tablets February 23, 2016

    order stromectol 6mg

    stromectol 12mg online

  • cialis over the counter walmart February 23, 2016

    what is monthly cost of cialis at walmart

    cost of cialis at walmart

  • are eggs keto February 23, 2016

    how to follow a keto diet

  • free sugar momma dating website February 23, 2016

    free muslim dating uk

  • free us online dating site February 23, 2016

    free foreign dating sites

  • free on line sex chat and dating sites February 23, 2016

    free online dating site in us

  • zithromax liquid February 23, 2016

    buy zithromax without a doctor

    zithromax kidney pain

  • taking levitra with vitamens February 23, 2016

    levitra 20mg dissolve on togue or take with water

    levitra reviews by men

  • stromectol cheap February 23, 2016

    stromectol dosage weight

    stromectol merck scabies

  • online cialis without a prescription February 23, 2016

    cialis without a prescription?

    do you need a prescription for cialis in canada

  • ivermectin for goats February 23, 2016

    stromectol buy online uk

    stromectol cost

  • sildenafil taken for ed February 23, 2016

    sildenafil 100mg tablets generic

    forhim.com sildenafil

  • phenibut and cymbalta February 23, 2016

    phenibut and cymbalta

    phenibut and cymbalta

  • cymbalta and wellbutrin February 23, 2016

    cymbalta and wellbutrin

    cymbalta and wellbutrin

  • can i give my dog cephalexin 500 mg February 23, 2016

    can i give my dog cephalexin 500 mg

    can i give my dog cephalexin 500 mg

  • keflex sore throat February 23, 2016

    keflex sore throat

    keflex sore throat

  • celebrex and warfarin February 23, 2016

    celebrex and warfarin

    celebrex and warfarin

  • celebrex and aspirin February 23, 2016

    celebrex and aspirin

    celebrex and aspirin

  • cheap zithromax February 23, 2016

    cheap zithromax

    cheap zithromax

  • feline amoxicillin dosage February 23, 2016

    feline amoxicillin dosage

    feline amoxicillin dosage

  • amoxicillin powder February 23, 2016

    amoxicillin powder

    amoxicillin powder

  • cialis dosage reddit australia February 23, 2016

    cialis dosage reddit australia

    cialis dosage reddit australia

  • cheap cialis pills australia February 23, 2016

    cheap cialis pills australia

    cheap cialis pills australia

  • generic cialis drugstore February 23, 2016

    generic cialis drugstore

    generic cialis drugstore

  • viagra 50 mg price February 23, 2016

    viagra 50 mg price

    viagra 50 mg price

  • cialis online canada paypal February 23, 2016

    cialis online canada paypal

    cialis online canada paypal

  • cialis erection australia February 23, 2016

    cialis erection australia

    cialis erection australia

  • cialis tadalafil uses February 23, 2016

    cialis tadalafil uses

    cialis tadalafil uses

  • taking viagra before and after February 23, 2016

    taking viagra before and after

    taking viagra before and after

  • uses for cialis February 23, 2016

    uses for cialis

    uses for cialis

  • what is cialis professional February 23, 2016

    what is cialis professional

    what is cialis professional

  • song from cialis commercial that look February 23, 2016

    song from cialis commercial that look

    song from cialis commercial that look

  • cipla cialis review February 23, 2016

    cipla cialis review

    cipla cialis review

  • viagra pranks on guys February 23, 2016

    viagra pranks on guys

    viagra pranks on guys

  • natural chinese viagra February 23, 2016

    natural chinese viagra

    natural chinese viagra

  • cheapest 20 mg cialis and dapoxetine February 23, 2016

    cheapest 20 mg cialis and dapoxetine

    cheapest 20 mg cialis and dapoxetine

  • womens viagra pill reviews February 23, 2016

    womens viagra pill reviews

    womens viagra pill reviews

  • liquid viagra February 23, 2016

    liquid viagra

    liquid viagra

  • vardenafil February 23, 2016

    vardenafil

    vardenafil

  • cialis cost per pill February 23, 2016

    cialis cost per pill

    cialis cost per pill

  • how to use cialis February 23, 2016

    how to use cialis

    how to use cialis

  • viagra boner porn February 23, 2016

    viagra boner porn

    viagra boner porn

  • levitra dosage February 23, 2016

    levitra dosage

    levitra dosage

  • cheap viagra generic February 23, 2016

    cheap viagra generic

    cheap viagra generic

  • viagra on line no prec February 23, 2016

    viagra on line no prec

    viagra on line no prec

  • is viagra safe to take February 23, 2016

    is viagra safe to take

    is viagra safe to take

  • sister viagra February 23, 2016

    sister viagra

    sister viagra

  • viagra gay sex February 23, 2016

    viagra gay sex

    viagra gay sex

  • viagra meaning February 23, 2016

    viagra meaning

    viagra meaning

  • viagra from canada February 23, 2016

    viagra from canada

    viagra from canada

  • viagra pas cher February 23, 2016

    viagra pas cher

    viagra pas cher

  • coupons for viagra February 23, 2016

    coupons for viagra

    coupons for viagra

  • viagra 100 mg price February 23, 2016

    viagra 100 mg price

    viagra 100 mg price

  • generic tadalafil February 23, 2016

    generic tadalafil

    generic tadalafil

  • cheap cialis generic February 23, 2016

    cheap cialis generic

    cheap cialis generic

  • avanafil vs viagra February 23, 2016

    avanafil vs viagra

    avanafil vs viagra

  • cialis for women February 23, 2016

    cialis for women

    cialis for women

  • viagra without a doctor prescription February 23, 2016

    buy viagra

    diferencia entre viagra y viagra – viagra and alcohol mix it is currently – viagra 20mg dosage announcements

  • cialis canada February 23, 2016

    cialis canada

    cialis 20 mg 8 table posts per day – cialis 5 mg online profile – cialis pills disclaimer of warranties

  • tadalafil online February 23, 2016

    tadalafil 20 mg

    no prescription india generic cialis – cialis one a day – cialis dosage for bph guests

  • levitra online February 23, 2016

    buy levitra

    when to take levitra – levitra 20mg tablets all times are utc – levitra dose