aws / serverless-application-model

The AWS Serverless Application Model (AWS SAM) transform is a AWS CloudFormation macro that transforms SAM templates into CloudFormation templates.
https://aws.amazon.com/serverless/sam
Apache License 2.0
9.36k stars 2.38k forks source link

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

Open lskrajny opened 5 years ago

lskrajny commented 5 years ago

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

keetonian commented 5 years ago

@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.

lskrajny commented 5 years ago

Sent a PR, let me know if all good

ShreyaGangishetty commented 4 years ago

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

keetonian commented 4 years ago

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.
    1. V1: template deploys, but, like I found today, the tags are not added to the resource.
    2. V2: template does not deploy and fails with an explicit error. This is the desired behavior
  2. 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.

Slooz commented 4 years ago

@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?

praneetap commented 4 years ago

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

dkasyanov commented 4 years ago

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)?

zz commented 4 years ago

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

godrose commented 4 years ago

This is a showstopper for us. Any ETA?

bengwall commented 4 years ago

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

siliconsheep commented 3 years ago

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

rdok commented 2 years ago

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

ehicks71 commented 1 month ago

Any progress on this? I'm still seeing this as an issue. I'm using SAM CLI v1.72.0