serverless.yml
file and swap creds for the client. Now, first, let's say we have this mapping template. I'm not going into the syntax for mapping templates in this post (future post, maybe). Though, try to step through it and I think you'll understand!:// api-mapping-template.vtl{ "body" : $input.json('$'), "headers": { #foreach($header in $input.params().header.keySet()) "$header": "$util.escapeJavaScript($input.params().header.get($header))" #if($foreach.hasNext),#end #end }, "method": "$context.httpMethod", "params": { #foreach($param in $input.params().path.keySet()) "$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end #end }, "query": { #foreach($queryParam in $input.params().querystring.keySet()) "$queryParam": "$util.escapeJavaScript($input.params().querystring.get($queryParam))" #if($foreach.hasNext),#end #end }}
headers
, query
, and params
from the request hitting API Gateway and pops them onto the event
argument that is eventually passed into my Lambda handler
method. Phew! Now, I have two options for "deploying" this template:serverless.yml
for deploymentfunction
definition in your serverless.yml
file. I'm sure there's a way to inline it, but, even better, you can use the awesome ${file()}
variable method to reference an external .vtl
file and have it packaged up with your CloudFormation template.functions: doTheThing: handler: deployment/src/handler.doTheThing events: - http: path: /do-thing method: get integration: lambda request: template: application/json: ${file(./mapping-templates/api-gateway-mapping-template.vtl)}