Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support API Gateway stage deployment description #5509

Merged
merged 14 commits into from
Mar 7, 2019
6 changes: 6 additions & 0 deletions docs/providers/aws/events/apigateway.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ provider:
apiGateway: apiGateway:
restApiId: xxxxxxxxxx # REST API resource ID. Default is generated by the framework restApiId: xxxxxxxxxx # REST API resource ID. Default is generated by the framework
restApiRootResourceId: xxxxxxxxxx # Root resource, represent as / path restApiRootResourceId: xxxxxxxxxx # Root resource, represent as / path
description: Some Description # optional - description of deployment history


functions: functions:
... ...
Expand All @@ -996,6 +997,7 @@ provider:
apiGateway: apiGateway:
restApiId: xxxxxxxxxx restApiId: xxxxxxxxxx
restApiRootResourceId: xxxxxxxxxx restApiRootResourceId: xxxxxxxxxx
description: Some Description


functions: functions:
create: create:
Expand All @@ -1012,6 +1014,7 @@ provider:
apiGateway: apiGateway:
restApiId: xxxxxxxxxx restApiId: xxxxxxxxxx
restApiRootResourceId: xxxxxxxxxx restApiRootResourceId: xxxxxxxxxx
description: Some Description


functions: functions:
create: create:
Expand All @@ -1030,6 +1033,7 @@ provider:
apiGateway: apiGateway:
restApiId: xxxxxxxxxx restApiId: xxxxxxxxxx
restApiRootResourceId: xxxxxxxxxx restApiRootResourceId: xxxxxxxxxx
description: Some Description
restApiResources: restApiResources:
/posts: xxxxxxxxxx /posts: xxxxxxxxxx


Expand All @@ -1044,6 +1048,7 @@ provider:
apiGateway: apiGateway:
restApiId: xxxxxxxxxx restApiId: xxxxxxxxxx
restApiRootResourceId: xxxxxxxxxx restApiRootResourceId: xxxxxxxxxx
description: Some Description
restApiResources: restApiResources:
/posts: xxxxxxxxxx /posts: xxxxxxxxxx


Expand All @@ -1061,6 +1066,7 @@ provider:
apiGateway: apiGateway:
restApiId: xxxxxxxxxx restApiId: xxxxxxxxxx
# restApiRootResourceId: xxxxxxxxxx # Optional # restApiRootResourceId: xxxxxxxxxx # Optional
description: Some Description
restApiResources: restApiResources:
/posts: xxxxxxxxxx /posts: xxxxxxxxxx
/categories: xxxxxxxxx /categories: xxxxxxxxx
Expand Down
1 change: 1 addition & 0 deletions docs/providers/aws/guide/serverless.yml.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ provider:
'/users/create': xxxxxxxxxx '/users/create': xxxxxxxxxx
apiKeySourceType: HEADER # Source of API key for usage plan. HEADER or AUTHORIZER. apiKeySourceType: HEADER # Source of API key for usage plan. HEADER or AUTHORIZER.
minimumCompressionSize: 1024 # Compress response when larger than specified size in bytes (must be between 0 and 10485760) minimumCompressionSize: 1024 # Compress response when larger than specified size in bytes (must be between 0 and 10485760)
description: Some Description # optional description for the API Gateway stage deployment
usagePlan: # Optional usage plan configuration usagePlan: # Optional usage plan configuration
quota: quota:
limit: 5000 limit: 5000
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
Properties: { Properties: {
RestApiId: this.provider.getApiGatewayRestApiId(), RestApiId: this.provider.getApiGatewayRestApiId(),
StageName: this.provider.getStage(), StageName: this.provider.getStage(),
Description: this.provider.getApiGatewayDescription(),
Copy link
Contributor

@softprops softprops Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking up because I thing this feature will actually fix #3495 (comment) if implemented correctly.

The cloud formation resource for this is not a string but a structured type
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-deployment.html

It's the structured type that enables turning on active tracing for the gateway https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-deployment-stagedescription.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take that back. That's StageDescription vs Description. You may get more bang for your buck if you add them both here. I'd but happy to add a follow pull that just mirrors this with StageDescription if that's too much scope.

Copy link
Contributor Author

@vkkis93 vkkis93 Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can add StageDescription
I will create new PR which will be based on this one

UPD: I have looked on stage description and it's very complex task.
I would like to do it but not right now.
Can we finish the first with this PR ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if it only sets the description if it's provided instead of setting it to an empty string if it's not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dschep I've done

}, },
DependsOn: this.apiGatewayMethodLogicalIds, DependsOn: this.apiGatewayMethodLogicalIds,
}, },
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,12 +44,42 @@ describe('#compileDeployment()', () => {
RestApiId: { RestApiId: {
Ref: awsCompileApigEvents.apiGatewayRestApiLogicalId, Ref: awsCompileApigEvents.apiGatewayRestApiLogicalId,
}, },
Description: undefined,
StageName: 'dev', StageName: 'dev',
}, },
}); });
}) })
); );


it('should create a deployment resource with description', () => {
awsCompileApigEvents.serverless.service.provider.apiGateway = {
description: 'Some Description',
};

return awsCompileApigEvents
.compileDeployment().then(() => {
const apiGatewayDeploymentLogicalId = Object
.keys(awsCompileApigEvents.serverless.service.provider
.compiledCloudFormationTemplate.Resources)[0];

expect(
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
.Resources[apiGatewayDeploymentLogicalId]
).to.deep.equal({
Type: 'AWS::ApiGateway::Deployment',
DependsOn: ['method-dependency1', 'method-dependency2'],
Properties: {
RestApiId: {
Ref: awsCompileApigEvents.apiGatewayRestApiLogicalId,
},
Description: 'Some Description',
StageName: 'dev',
},
});
});
}
);

it('should add service endpoint output', () => it('should add service endpoint output', () =>
awsCompileApigEvents.compileDeployment().then(() => { awsCompileApigEvents.compileDeployment().then(() => {
expect( expect(
Expand Down
8 changes: 8 additions & 0 deletions lib/plugins/aws/provider/awsProvider.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ class AwsProvider {
return { Ref: this.naming.getRestApiLogicalId() }; return { Ref: this.naming.getRestApiLogicalId() };
} }


getApiGatewayDescription() {
if (this.serverless.service.provider.apiGateway
&& this.serverless.service.provider.apiGateway.description) {
return this.serverless.service.provider.apiGateway.description;
}
return undefined;
}

getMethodArn(accountId, apiId, method, pathParam) { getMethodArn(accountId, apiId, method, pathParam) {
const region = this.getRegion(); const region = this.getRegion();
let path = pathParam; let path = pathParam;
Expand Down