Skip to content

Commit

Permalink
Merge pull request #7039 from serverless/fix-custom-rest-api-id-handling
Browse files Browse the repository at this point in the history
Fix resolution of user configured APIGW
  • Loading branch information
medikoo committed Dec 3, 2019
2 parents d28ac9d + ad59d22 commit 44115aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Expand Up @@ -99,7 +99,7 @@ function resolveAccountInfo() {
function resolveApiGatewayResource(resources) {
if (resources.ApiGatewayRestApi) return resources.ApiGatewayRestApi;
const apiGatewayResources = _.values(resources).filter(
resource => resource.Type === 'AWS::ApiGateway::Resource'
resource => resource.Type === 'AWS::ApiGateway::RestApi'
);
if (apiGatewayResources.length === 1) return apiGatewayResources[0];
// None, or more than one API Gateway found (currently there's no support for multiple APIGW's)
Expand Down
Expand Up @@ -41,7 +41,7 @@ describe('#updateStage()', () => {
serverless.service.provider.compiledCloudFormationTemplate = {
Resources: {
ApiGatewayRestApi: {
Type: 'AWS::ApiGateway::Resource',
Type: 'AWS::ApiGateway::RestApi',
Properties: {
Name: 'dev-my-service',
},
Expand All @@ -65,6 +65,7 @@ describe('#updateStage()', () => {
items: [
{ name: 'dev-my-service', id: 'devRestApiId' },
{ name: 'prod-my-service', id: 'prodRestApiId' },
{ name: 'custom-rest-api-name', id: 'customRestApiId' },
],
});
providerRequestStub
Expand All @@ -87,6 +88,16 @@ describe('#updateStage()', () => {
old: 'tag',
},
});
providerRequestStub
.withArgs('APIGateway', 'getStage', {
restApiId: 'customRestApiId',
stageName: 'dev',
})
.resolves({
tags: {
old: 'tag',
},
});

providerRequestStub
.withArgs('CloudWatchLogs', 'deleteLogGroup', {
Expand Down Expand Up @@ -480,8 +491,9 @@ describe('#updateStage()', () => {
const resources = context.serverless.service.provider.compiledCloudFormationTemplate.Resources;
resources.CustomApiGatewayRestApi = resources.ApiGatewayRestApi;
delete resources.ApiGatewayRestApi;
resources.CustomApiGatewayRestApi.Properties.Name = 'custom-rest-api-name';
return updateStage.call(context).then(() => {
expect(context.apiGatewayRestApiId).to.equal('devRestApiId');
expect(context.apiGatewayRestApiId).to.equal('customRestApiId');
});
});

Expand Down

0 comments on commit 44115aa

Please sign in to comment.