Skip to content

Instantly share code, notes, and snippets.

@carlgieringer
Last active June 14, 2022 05:30
Show Gist options
  • Save carlgieringer/01f681a0ee8863568c5ed9325904fe5d to your computer and use it in GitHub Desktop.
Save carlgieringer/01f681a0ee8863568c5ed9325904fe5d to your computer and use it in GitHub Desktop.
AWS API Gateway Integration Request Lambda Proxy (LAMBDA_PROXY) Velocity Template Language (VTL)
## MIT License
##
## Copyright (c) 2017 Carl Gieringer
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all
## copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
## Designed to duplicate the default LAMBDA_PROXY behavior if you can't use LAMBDA_PROXY request integration for your Lambda
#set($allParams = $input.params())
#set($pathParams = $allParams.get('path'))
#set($queryStringParams = $allParams.get('querystring'))
#set($headerParams = $allParams.get('header'))
{
"body" : $input.json('$'),
"isBase64Encoded": false,
"resource": "$context.resourcePath",
"path": "$context.resourcePath.replace('{proxy+}', $pathParams.get('proxy'))",
"httpMethod": "$context.httpMethod",
"headers": {
#foreach($key in $headerParams.keySet())
"$key" : "$util.escapeJavaScript($headerParams).get($key))"
#if($foreach.hasNext),#end
#end
},
"queryStringParameters": {
#foreach($key in $queryStringParams.keySet())
"$key" : "$util.escapeJavaScript($queryStringParams.get($key))"
#if($foreach.hasNext),#end
#end
},
"pathParameters": {
#foreach($key in $pathParams.keySet())
"$key" : "$util.escapeJavaScript($pathParams.get($key))"
#if($foreach.hasNext),#end
#end
},
"stageVariables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
#if($foreach.hasNext),#end
#end
},
"requestContext": {
"accountId": "$context.accountId",
"resourceId": "$context.resourceId",
"stage": "$context.stage",
"requestId": "$context.requestId",
"resourcePath": "$context.resourcePath",
"httpMethod": "$context.httpMethod",
"apiId": "$context.apiId",
"authorizer": {
"principalId": "$context.authorizer.principalId"
},
"identity": {
"cognitoIdentityPoolId": "$context.identity.cognitoIdentityPoolId",
"accountId": "$context.identity.accountId",
"cognitoIdentityId": "$context.identity.cognitoIdentityId",
"caller": "$context.identity.caller",
"apiKey": "$context.identity.apiKey",
"sourceIp":"$context.identity.sourceIp",
"accessKey": "$context.identity.accessKey",
"cognitoAuthenticationType": "$context.identity.cognitoAuthenticationType",
"cognitoAuthenticationProvider": "$context.identity.cognitoAuthenticationProvider",
"userArn": "$context.identity.userArn",
"userAgent": "$context.identity.userAgent",
"user": "$context.identity.user"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment