Skip to content

Commit

Permalink
Merge pull request #1850 from patrickbrandt/master
Browse files Browse the repository at this point in the history
include stage reference in body mapping template
  • Loading branch information
pmuens committed Aug 15, 2016
2 parents a723544 + 2132e08 commit 417b8f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/guide/overview-of-event-sources.md
Expand Up @@ -109,6 +109,7 @@ in the `event` object:
- body
- method
- principalId
- stage
- headers
- query
- path
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/deploy/compile/events/apiGateway/README.md
Expand Up @@ -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.

Expand Down
11 changes: 10 additions & 1 deletion lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js
Expand Up @@ -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 )
Expand All @@ -102,6 +110,7 @@ module.exports = {
"body": $input.json("$"),
"method": "$context.httpMethod",
"principalId": "$context.authorizer.principalId",
"stage": "$context.stage",
#set( $map = $input.params().header )
"headers": $loop,
Expand Down

0 comments on commit 417b8f3

Please sign in to comment.