From 3ac14c6093e3df3359e8aef46817349540da92ff Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 2 Dec 2019 17:43:40 +0100 Subject: [PATCH 1/3] Do not update external APIGW configuration --- .../compile/events/apiGateway/lib/hack/updateStage.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js index 34d24e837..b01ef6e1d 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.js @@ -4,7 +4,6 @@ const _ = require('lodash'); const BbPromise = require('bluebird'); const ServerlessError = require('../../../../../../../../classes/Error').ServerlessError; -const isRestApiId = RegExp.prototype.test.bind(/^[a-z0-9]{3,}$/); const defaultApiGatewayLogFormat = [ 'requestId: $context.requestId', 'ip: $context.identity.sourceIp', @@ -42,6 +41,8 @@ module.exports = { .call(this) .then(resolveRestApiId.bind(this)) .then(() => { + // Do not update APIGW-wide settings, in case external APIGW is referenced + if (this.isExternalRestApi) return null; if (!this.apiGatewayRestApiId) { // Could not resolve REST API id automatically @@ -103,7 +104,8 @@ function resolveRestApiId() { const provider = this.state.service.provider; const externalRestApiId = provider.apiGateway && provider.apiGateway.restApiId; if (externalRestApiId) { - resolve(isRestApiId(externalRestApiId) ? externalRestApiId : null); + this.isExternalRestApi = true; + resolve(null); return; } const apiGatewayResource = resolveApiGatewayResource( From 212b0d145e80699295efda1be29a85b753ca175b Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 2 Dec 2019 17:48:18 +0100 Subject: [PATCH 2/3] Update test --- .../apiGateway/lib/hack/updateStage.test.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js index db646154e..4cf887409 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js @@ -454,20 +454,11 @@ describe('#updateStage()', () => { }); }); - it('should resolve custom restApiId', () => { - providerRequestStub - .withArgs('APIGateway', 'getStage', { - restApiId: 'foobarfoo1', - stageName: 'dev', - }) - .resolves({ - variables: { - old: 'tag', - }, - }); + it('should ignore external api gateway', () => { context.state.service.provider.apiGateway = { restApiId: 'foobarfoo1' }; return updateStage.call(context).then(() => { - expect(context.apiGatewayRestApiId).to.equal('foobarfoo1'); + expect(context.isExternalRestApi).to.equal(true); + expect(context.apiGatewayRestApiId).to.equal(null); }); }); From dea6ac36d467ee86e6b299f53f27960396087c72 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Tue, 3 Dec 2019 13:44:06 +0100 Subject: [PATCH 3/3] Update test after recent changes --- .../compile/events/apiGateway/lib/hack/updateStage.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js index c9edacb82..8d41fdbeb 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage.test.js @@ -440,6 +440,7 @@ describe('#updateStage()', () => { it('should ignore external api gateway', () => { context.state.service.provider.apiGateway = { restApiId: 'foobarfoo1' }; + context.state.service.provider.tracing = { apiGateway: false }; return updateStage.call(context).then(() => { expect(context.isExternalRestApi).to.equal(true); expect(context.apiGatewayRestApiId).to.equal(null);