Skip to content

Commit a907ba4

Browse files
Merge pull request #196 from horike37/feature/lambda_proxy_template_update
fix: address some diffs with lambda_proxy
2 parents e18eff3 + c9669ab commit a907ba4

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

lib/deploy/events/apiGateway/methods.js

+43-19
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,69 @@ const awsArnRegExs = require('../../../utils/arnRegularExpressions');
66

77
const LAMBDA_PROXY_REQUEST_TEMPLATE = `
88
#define( $loop )
9-
{
9+
{
1010
#foreach($key in $map.keySet())
11-
#set( $k = $util.escapeJavaScript($key) )
12-
#set( $v = $util.escapeJavaScript($map.get($key)).replaceAll("\\\\'", "'") )
13-
"$k":
11+
#set( $k = $util.escapeJavaScript($key) )
12+
#set( $v = $util.escapeJavaScript($map.get($key)).replaceAll("\\\\'", "'") )
13+
"$k":
14+
#if ("$v" == "")
15+
null
16+
#else
1417
"$v"
15-
#if( $foreach.hasNext ) , #end
18+
#end
19+
#if( $foreach.hasNext ) , #end
1620
#end
17-
}
21+
}
1822
#end
1923
#define( $smInput )
2024
{
21-
"body": $body,
22-
"httpMethod": "$context.httpMethod",
23-
"path": "$context.path",
2425
"resource": "$context.resourcePath",
26+
"path": "$context.path",
27+
"httpMethod": "$context.httpMethod",
2528
#set( $map = $input.params().header )
2629
"headers": $loop,
30+
31+
#if ($input.params().querystring.size() == 0)
32+
"queryStringParameters": null,
33+
#else
2734
#set( $map = $input.params().querystring )
2835
"queryStringParameters": $loop,
36+
#end
37+
38+
#if ($input.params().path.size() == 0)
39+
"pathParameters": null,
40+
#else
2941
#set( $map = $input.params().path )
3042
"pathParameters": $loop,
43+
#end
44+
45+
#if ($stageVariables.size() == 0)
46+
"stageVariables": null,
47+
#else
48+
#set( $map = $stageVariables )
49+
"stageVariables": $loop,
50+
#end
51+
3152
"requestContext": {
32-
"accountId": "\${AccountId}",
3353
"resourceId": "$context.resourceId",
34-
"stage": "$context.stage",
35-
"requestId": "$context.requestId",
54+
"resourcePath": "$context.resourcePath",
55+
"httpMethod": "$context.httpMethod",
56+
"extendedRequestId": "$context.extendedRequestId",
3657
"requestTime": "$context.requestTime",
58+
"path": "$context.path",
59+
"accountId": "\${AccountId}",
60+
"protocol": "$context.protocol",
61+
"stage": "$context.stage",
62+
"domainPrefix": "$context.domainPrefix",
3763
"requestTimeEpoch": "$context.requestTimeEpoch",
64+
"requestId": "$context.requestId",
3865
#set( $map = $context.identity )
3966
"identity": $loop,
40-
"path": "$context.path",
41-
"resourcePath": "$context.resourcePath",
42-
"httpMethod": "$context.httpMethod",
43-
"protocol": "$context.protocol",
67+
"domainName": "$context.domainName",
4468
"apiId": "$context.apiId"
4569
},
46-
#set( $map = $stageVariables )
47-
"stageVariables": $loop
70+
"body": "$util.escapeJavaScript("$body")",
71+
"isBase64Encoded": false
4872
}
4973
#end
5074
{
@@ -54,7 +78,7 @@ const LAMBDA_PROXY_REQUEST_TEMPLATE = `
5478
}`;
5579

5680
const LAMBDA_PROXY_JSON_REQUEST_TEMPLATE = `
57-
#set( $body = $input.json('$') )
81+
#set( $body = $input.body )
5882
${LAMBDA_PROXY_REQUEST_TEMPLATE}`;
5983

6084
const LAMBDA_PROXY_FORM_URL_ENCODED_REQUEST_TEMPLATE = `

lib/deploy/events/apiGateway/methods.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ describe('#methods()', () => {
239239
.getMethodIntegration('stateMachine', undefined, httpWithRequestTemplate)
240240
.Properties.Integration.RequestTemplates;
241241
expect(requestTemplates['application/json']['Fn::Sub'][0])
242-
.to.contain("#set( $body = $input.json('$') )");
242+
.to.contain('#set( $body = $input.body )');
243243
expect(requestTemplates['application/json']['Fn::Sub'][1])
244244
.to.be.deep.equal({
245245
StateMachineArn: { Ref: 'StateMachineStepFunctionsStateMachine' },

0 commit comments

Comments
 (0)