From 052b8c3c19d6eeb9425eb0953f8b896c1afbe418 Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Sun, 14 Aug 2016 15:33:53 -0400 Subject: [PATCH 1/5] include stage reference in body mapping template I've included a stage reference in the body template so that I can determine the run-time environment of the lambda function. This provide a quick work around until issue #1455 is resolved --- lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js index 932491e9e81..5945e7413b1 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js @@ -102,6 +102,7 @@ module.exports = { "body": $input.json("$"), "method": "$context.httpMethod", "principalId": "$context.authorizer.principalId", + "stage": "$context.stage", #set( $map = $input.params().header ) "headers": $loop, From 2db9034ef5059bf12bb775eaf96880a9250bbb71 Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Mon, 15 Aug 2016 09:49:12 -0400 Subject: [PATCH 2/5] updating docs per PR #1850 --- docs/guide/overview-of-event-sources.md | 1 + lib/plugins/aws/deploy/compile/events/apiGateway/README.md | 2 +- lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/guide/overview-of-event-sources.md b/docs/guide/overview-of-event-sources.md index 6a46a6e7406..e7484a75d05 100644 --- a/docs/guide/overview-of-event-sources.md +++ b/docs/guide/overview-of-event-sources.md @@ -109,6 +109,7 @@ in the `event` object: - body - method - principalId +- stage - headers - query - path diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/README.md b/lib/plugins/aws/deploy/compile/events/apiGateway/README.md index 1c5515b91ec..8b413761adf 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/README.md +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/README.md @@ -18,7 +18,7 @@ Those resources are then merged into the `serverless.service.resources.Resources ## Universal JSON request template -The API Gateway plugin implements a request template which provides `{body, method, principalId, headers, query, path, identity, +The API Gateway plugin implements a request template which provides `{body, method, principalId, stage, headers, query, path, identity, stageVariables} = event` as JavaScript objects. This way you don't have to define the template on your own but can use this default template to access the necessary variables in your code. diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js index 5945e7413b1..f4b8aa501f1 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js @@ -86,7 +86,7 @@ module.exports = { // universal velocity template // provides - // `{body, method, principalId, headers, query, path, identity, stageVariables} = event` + // `{body, method, principalId, stage, headers, query, path, identity, stageVariables} = event` // as js objects const DEFAULT_JSON_REQUEST_TEMPLATE = ` #define( $loop ) From c27cc5292cadd63cc821e3f41722ebd1768d7ee4 Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Mon, 15 Aug 2016 10:05:04 -0400 Subject: [PATCH 3/5] fixing failed build due to lint issue (max 100 chars per line) - this on the comment I just edited --- .../deploy/compile/events/apiGateway/lib/methods.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js index f4b8aa501f1..be548607b66 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js @@ -86,7 +86,15 @@ module.exports = { // universal velocity template // provides - // `{body, method, principalId, stage, headers, query, path, identity, stageVariables} = event` + // `{ body, + // method, + // principalId, + // stage, + // headers, + // query, + // path, + // identity, + // stageVariables} = event` // as js objects const DEFAULT_JSON_REQUEST_TEMPLATE = ` #define( $loop ) From f962d8e11c535ae599572089acfc618120c732c0 Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Mon, 15 Aug 2016 10:10:21 -0400 Subject: [PATCH 4/5] removing trailing spaces --- .../compile/events/apiGateway/lib/methods.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js index be548607b66..c868155051f 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js @@ -86,14 +86,14 @@ module.exports = { // universal velocity template // provides - // `{ body, - // method, - // principalId, - // stage, - // headers, - // query, - // path, - // identity, + // `{ body, + // method, + // principalId, + // stage, + // headers, + // query, + // path, + // identity, // stageVariables} = event` // as js objects const DEFAULT_JSON_REQUEST_TEMPLATE = ` From 13efa0e2acd17fe65e39236cec8dd1a8448150cb Mon Sep 17 00:00:00 2001 From: Patrick Brandt Date: Mon, 15 Aug 2016 09:49:12 -0400 Subject: [PATCH 5/5] updating docs per PR #1850 --- docs/guide/overview-of-event-sources.md | 1 + .../aws/deploy/compile/events/apiGateway/README.md | 2 +- .../deploy/compile/events/apiGateway/lib/methods.js | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/guide/overview-of-event-sources.md b/docs/guide/overview-of-event-sources.md index 6a46a6e7406..e7484a75d05 100644 --- a/docs/guide/overview-of-event-sources.md +++ b/docs/guide/overview-of-event-sources.md @@ -109,6 +109,7 @@ in the `event` object: - body - method - principalId +- stage - headers - query - path diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/README.md b/lib/plugins/aws/deploy/compile/events/apiGateway/README.md index 1c5515b91ec..8b413761adf 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/README.md +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/README.md @@ -18,7 +18,7 @@ Those resources are then merged into the `serverless.service.resources.Resources ## Universal JSON request template -The API Gateway plugin implements a request template which provides `{body, method, principalId, headers, query, path, identity, +The API Gateway plugin implements a request template which provides `{body, method, principalId, stage, headers, query, path, identity, stageVariables} = event` as JavaScript objects. This way you don't have to define the template on your own but can use this default template to access the necessary variables in your code. diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js index 5945e7413b1..c868155051f 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js @@ -86,7 +86,15 @@ module.exports = { // universal velocity template // provides - // `{body, method, principalId, headers, query, path, identity, stageVariables} = event` + // `{ body, + // method, + // principalId, + // stage, + // headers, + // query, + // path, + // identity, + // stageVariables} = event` // as js objects const DEFAULT_JSON_REQUEST_TEMPLATE = ` #define( $loop )