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 b8c66b768..284168f67 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', @@ -52,6 +51,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 @@ -110,7 +111,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( 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 c19813c1b..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 @@ -438,21 +438,12 @@ describe('#updateStage()', () => { }); }); - it('should resolve custom restApiId', () => { - context.state.service.provider.tracing = { apiGateway: false }; - 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' }; + context.state.service.provider.tracing = { apiGateway: false }; return updateStage.call(context).then(() => { - expect(context.apiGatewayRestApiId).to.equal('foobarfoo1'); + expect(context.isExternalRestApi).to.equal(true); + expect(context.apiGatewayRestApiId).to.equal(null); }); });