Skip to content

Commit

Permalink
fix(AWS HTTP API): Ensure to apply tags to stage (#9407)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipgolonka committed May 3, 2021
1 parent 6d2ed84 commit 80511a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/providers/aws/events/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ provider:

### Tags

When using HTTP API, it is possible to tag the corresponding API Gateway. By setting `provider.httpApi.useProviderTags` to `true`, all tags defined on `provider.tags` will be applied to API Gateway.
When using HTTP API, it is possible to tag the corresponding API Gateway resources. By setting `provider.httpApi.useProviderTags` to `true`, all tags defined on `provider.tags` will be applied to API Gateway and API Gateway Stage.

```yaml
provider:
Expand All @@ -416,6 +416,6 @@ provider:
useProviderTags: true
```

In the above example, the tag project: myProject will be applied to API Gateway.
In the above example, the tag project: myProject will be applied to API Gateway and API Gateway Stage.

_Note: If the API Gateway has any existing tags applied outside of Serverless Framework, they will be removed during deployment._
8 changes: 8 additions & 0 deletions lib/plugins/aws/package/compile/events/httpApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ class HttpApiEvents {
},
};

if (
this.serverless.service.provider.tags &&
this.serverless.service.provider.httpApi &&
this.serverless.service.provider.httpApi.useProviderTags
) {
properties.Tags = Object.assign({}, this.serverless.service.provider.tags);
}

const resource = (this.cfTemplate.Resources[this.provider.naming.getHttpApiStageLogicalId()] = {
Type: 'AWS::ApiGatewayV2::Stage',
Properties: properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ describe('lib/plugins/aws/package/compile/events/httpApi.test.js', () => {
const { Tags } = cfApi.Properties;
expect(Tags).to.be.a('object');
expect(Tags).to.deep.equal(expectedTags);

const { Tags: stageTags } = cfStage.Properties;
expect(stageTags).to.be.a('object');
expect(stageTags).to.deep.equal(expectedTags);
});

it('should set payload format version', () => {
Expand Down

0 comments on commit 80511a4

Please sign in to comment.