diff --git a/src/events/http/HttpServer.js b/src/events/http/HttpServer.js index d64aba205..9d26f6305 100644 --- a/src/events/http/HttpServer.js +++ b/src/events/http/HttpServer.js @@ -472,10 +472,14 @@ export default class HttpServer { event = request.payload || {} } } else if (integration === 'AWS_PROXY') { + const stageVariables = this.#serverless.service.custom + ? this.#serverless.service.custom.stageVariables + : null const lambdaProxyIntegrationEvent = new LambdaProxyIntegrationEvent( request, this.#serverless.service.provider.stage, requestPath, + stageVariables, ) event = lambdaProxyIntegrationEvent.create() diff --git a/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js b/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js index f65056cbd..e1314785d 100644 --- a/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js +++ b/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js @@ -21,11 +21,13 @@ export default class LambdaProxyIntegrationEvent { #path = null #request = null #stage = null + #stageVariables = null - constructor(request, stage, path) { + constructor(request, stage, path, stageVariables) { this.#path = path this.#request = request this.#stage = stage + this.#stageVariables = stageVariables } create() { @@ -185,7 +187,7 @@ export default class LambdaProxyIntegrationEvent { stage: this.#stage, }, resource: this.#path, - stageVariables: null, + stageVariables: this.#stageVariables, } } } diff --git a/tests/old-unit/LambdaProxyIntegrationEvent.test.js b/tests/old-unit/LambdaProxyIntegrationEvent.test.js index 83c364018..1d8041673 100644 --- a/tests/old-unit/LambdaProxyIntegrationEvent.test.js +++ b/tests/old-unit/LambdaProxyIntegrationEvent.test.js @@ -676,4 +676,26 @@ describe('LambdaProxyIntegrationEvent', () => { ).toEqual('customCognitoAuthenticationProvider') }) }) + + describe('with stage variables', () => { + test('should assign the value to stageVariables', () => { + const requestBuilder = new RequestBuilder('POST', '/fn1') + requestBuilder.addBody({ key: 'value' }) + requestBuilder.addHeader('content-type', 'custom/test') + const request = requestBuilder.toObject() + const path = 'path' + const stageVariables = 'stageVariables' + + const lambdaProxyIntegrationEvent = new LambdaProxyIntegrationEvent( + request, + stage, + path, + stageVariables, + ).create() + + expect(lambdaProxyIntegrationEvent.stageVariables).toEqual( + 'stageVariables', + ) + }) + }) })