Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/plugins/aws/package/compile/events/api-gateway/lib/rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,27 @@ module.exports = {
const DisableExecuteApiEndpoint =
apiGateway.disableDefaultEndpoint == null ? undefined : apiGateway.disableDefaultEndpoint;

const properties = {
Name: this.provider.naming.getApiGatewayName(),
BinaryMediaTypes,
DisableExecuteApiEndpoint,
EndpointConfiguration,
};

// Tags
if (this.serverless.service.provider.tags) {
properties.Tags = Object.entries(this.serverless.service.provider.tags).map(
([Key, Value]) => ({
Key,
Value,
})
);
}

_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
[this.apiGatewayRestApiLogicalId]: {
Type: 'AWS::ApiGateway::RestApi',
Properties: {
Name: this.provider.naming.getApiGatewayName(),
BinaryMediaTypes,
DisableExecuteApiEndpoint,
EndpointConfiguration,
},
Properties: properties,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ describe('#compileRestApi()', () => {
});
});

it('should create a REST API resource with tags', () => {
awsCompileApigEvents.serverless.service.provider.tags = {
tagKey1: 'tagValue1',
tagKey2: 'tagValue2',
};

awsCompileApigEvents.compileRestApi();
const resources =
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources;

expect(resources.ApiGatewayRestApi).to.deep.equal({
Type: 'AWS::ApiGateway::RestApi',
Properties: {
BinaryMediaTypes: undefined,
DisableExecuteApiEndpoint: undefined,
Name: 'dev-new-service',
EndpointConfiguration: {
Types: ['EDGE'],
},
Policy: '',
Tags: [
{ Key: 'tagKey1', Value: 'tagValue1' },
{ Key: 'tagKey2', Value: 'tagValue2' },
],
},
});
});

it('should create a REST API resource with resource policy', () => {
awsCompileApigEvents.serverless.service.provider.apiGateway = {
resourcePolicy: [
Expand Down