Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include stage reference in body mapping template #1850

Merged
merged 6 commits into from Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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