serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

AWS::Serverless::Api Tags are not visible in the API Gateway console under "Configure Tags"

Open lskrajny opened this issue 6 years ago • 13 comments

Description:

Steps to reproduce the issue:

  1. Prepare a SAM template with tags configured for API, eg:

     "ApiGatewayRestApi": {
         "Properties": {
             "Name": "Inbox",
             "Tags": [
                 {
                     "Key": "custom:stack-name",
                     "Value": {
                         "Ref": "AWS::StackName"
                     }
                 },
                 {
                     "Key": "custom:resource-name",
                     "Value": {
                         "Fn::Sub": "${AWS::StackName}-ApiGatewayRestApi"
                     }
                 }
             ]
         },
         "Type": "AWS::Serverless::Api"
     }
    
  2. Use aws cloudfromation package and then deploy to deploy the template

  3. Go to API Gateway console and there is nothing under "Configure Tags"

Observed result: No tags Expected result: 2 custom tags should be visible

lskrajny avatar Nov 12 '19 14:11 lskrajny

@lskrajny it looks like we haven't configured the output AWS::ApiGateway::RestApi resource to have those tags. This would be a very simple change to make.

Changes to support this: Add the tags field here: https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/model/apigateway.py#L23

Add it to the RestApi resource: https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/model/api/api_generator.py#L87

(Example of adding them to the stage: https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/model/api/api_generator.py#L212-L213)

Update tests.

keetonian avatar Nov 12 '19 18:11 keetonian

Sent a PR, let me know if all good

lskrajny avatar Nov 13 '19 13:11 lskrajny

@lskrajny there is a merge conflict in the PR. Could you please resolve it and update the PR?

ShreyaGangishetty avatar Dec 05 '19 23:12 ShreyaGangishetty

I reviewed your PR and tried deploying a template with the changes (details in #1244), and found that Tags were not added to the ApiGateway RestApi resource (but were successfully added to the ApiGateway Stage resource, like is currently implemented in SAM).

I discussed adding tags to both the V1 RestApi and V2 Api resource with ApiGateway and asked why it didn't work. Here are the main takeaways:

  1. Adding tags to the RestApi/Api resource when using OpenApi/Swagger to define an API is not currently supported on either V1 or V2 APIs.
  2. V1: template deploys, but, like I found today, the tags are not added to the resource.
  3. V2: template does not deploy and fails with an explicit error. This is the desired behavior
  4. There is a concept of tags in the OpenApi spec. ApiGateway may add support for adding tags in the OpenApi document. If this happens, we can likely support tags on both V1/V2 resources. This is pending a deeper dive from their team to see if this is possible.

I'll keep this thread updated as we chase this down. In the meantime, it looks like it isn't yet possible in SAM to support adding tags to the AWS::ApiGateway::RestApi resource.

keetonian avatar Dec 06 '19 22:12 keetonian

@keetonian, you're right that for V1, tags aren't added to the resource upon initial deployment. However, if you change the value of the tag and update the stack, the tag is added to the resource. Obviously, this is still a bug, and I reported this behavior to AWS.

But does this mean that adding tags to the RestApi/Api resource when using OpenApi/Swagger to define an API is supported for V1? Is there simply a bug where CloudFormation fails to deploy the initial tag?

Slooz avatar Jan 29 '20 22:01 Slooz

@Slooz Support for V2 to add tags in openapi is coming soon in SAM.

praneetap avatar Feb 19 '20 19:02 praneetap

I see that both V1 and V2 APIs have ability to add tags to the Api and RestApi. Is there any possibility that SAM will also have functionality to add tags toe Api (not the Stage)?

dkasyanov avatar Jun 30 '20 09:06 dkasyanov

Also can't tag Api in SAM 1.0.0. only stage tagged.

zz avatar Aug 02 '20 09:08 zz

This is a showstopper for us. Any ETA?

godrose avatar Aug 02 '20 15:08 godrose

Also wondering if we can get an update as to when this will be fixed.

bengwall avatar Aug 27 '20 17:08 bengwall

Hi! Still seems to be an issue today, any ETA on a fix / workaround?

siliconsheep avatar Jan 04 '21 13:01 siliconsheep

This issue still persists as of SAM CLI version 1.36.0.

However, auto generated tags from AWS SAM are actually DO properly work. This is important, because these tags cover the majority of uses cases including bill cost tags & least priveleges IAM policies.

For the auto generated tags to work, tags/* resources must be authorised.

2022-01-02 05_01_11-API Gateway — Mozilla Firefox

rdok avatar Jan 02 '22 05:01 rdok