Skip to content

Commit 4c48292

Browse files
authored
Merge pull request #107 from tazorax/add-rest-api-tags
Fix provider tags on `AWS::ApiGateway::RestApi`
2 parents d677c18 + b7f78f1 commit 4c48292

File tree

2 files changed

+46
-6
lines changed
  • lib/plugins/aws/package/compile/events/api-gateway/lib
  • test/unit/lib/plugins/aws/package/compile/events/api-gateway/lib

2 files changed

+46
-6
lines changed

lib/plugins/aws/package/compile/events/api-gateway/lib/rest-api.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,27 @@ module.exports = {
4747
const DisableExecuteApiEndpoint =
4848
apiGateway.disableDefaultEndpoint == null ? undefined : apiGateway.disableDefaultEndpoint;
4949

50+
const properties = {
51+
Name: this.provider.naming.getApiGatewayName(),
52+
BinaryMediaTypes,
53+
DisableExecuteApiEndpoint,
54+
EndpointConfiguration,
55+
};
56+
57+
// Tags
58+
if (this.serverless.service.provider.tags) {
59+
properties.Tags = Object.entries(this.serverless.service.provider.tags).map(
60+
([Key, Value]) => ({
61+
Key,
62+
Value,
63+
})
64+
);
65+
}
66+
5067
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
5168
[this.apiGatewayRestApiLogicalId]: {
5269
Type: 'AWS::ApiGateway::RestApi',
53-
Properties: {
54-
Name: this.provider.naming.getApiGatewayName(),
55-
BinaryMediaTypes,
56-
DisableExecuteApiEndpoint,
57-
EndpointConfiguration,
58-
},
70+
Properties: properties,
5971
},
6072
});
6173

test/unit/lib/plugins/aws/package/compile/events/api-gateway/lib/rest-api.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ describe('#compileRestApi()', () => {
5656
});
5757
});
5858

59+
it('should create a REST API resource with tags', () => {
60+
awsCompileApigEvents.serverless.service.provider.tags = {
61+
tagKey1: 'tagValue1',
62+
tagKey2: 'tagValue2',
63+
};
64+
65+
awsCompileApigEvents.compileRestApi();
66+
const resources =
67+
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources;
68+
69+
expect(resources.ApiGatewayRestApi).to.deep.equal({
70+
Type: 'AWS::ApiGateway::RestApi',
71+
Properties: {
72+
BinaryMediaTypes: undefined,
73+
DisableExecuteApiEndpoint: undefined,
74+
Name: 'dev-new-service',
75+
EndpointConfiguration: {
76+
Types: ['EDGE'],
77+
},
78+
Policy: '',
79+
Tags: [
80+
{ Key: 'tagKey1', Value: 'tagValue1' },
81+
{ Key: 'tagKey2', Value: 'tagValue2' },
82+
],
83+
},
84+
});
85+
});
86+
5987
it('should create a REST API resource with resource policy', () => {
6088
awsCompileApigEvents.serverless.service.provider.apiGateway = {
6189
resourcePolicy: [

0 commit comments

Comments
 (0)