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 932491e9e81..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 ) @@ -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,