question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[apigateway] Tags do not propagate to API Gateway resource when using openAPI spec (SpecRestApi)

See original GitHub issue

When creating a stack containing a SpecRestApi resource (an API Gateway resource the uses an Open API specification to define the API), if you add tags to the stack, those tags are NOT applied to the API upon creation.

Reproduction Steps

An Open API specification openApiSpecification.json:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Person API",
    "version": "0.0.1"
  },
  "components": {
    "schemas": {
      "Person": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "department": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/person": {
      "get": {
        "summary": "Returns a list of people.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Person"
                  }
                }
              }
            }
          }
        },
        "x-amazon-apigateway-integration": {
          "type": "mock",
          "responses": {
            "default": {
              "statusCode": "200"
            }
          },
          "requestTemplates": {
            "application/json": "{\"statusCode\": 200}"
          },
          "passthroughBehavior": "when_no_match"
        }
      }
    }
  }
}

A stack containing a SpecRestApi resource api-tags-demo-stack.ts:

export class ApiTagsDemoStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new apiGateway.SpecRestApi(this, 'apiDemoRestApi', {
      apiDefinition: apiGateway.ApiDefinition.fromAsset('openApiSpecification.json'),
    });

  }
}

Apply tags to the stack api-tags-demo.ts:

const app = new cdk.App();
const stack = new ApiTagsDemoStack(app, 'ApiTagsDemoStack');
Tags.of(stack).add("a", "b");
Tags.of(stack).add("c", "d");

Run cdk deploy and CDK successfully applies the tags to the stack:

image

But those tags are not present on the API resource:

image

What did you expect to happen?

The tags applied to the stack are applied to the API

What actually happened?

The tags applied to the stack have not been applied to the API.

If you add some more tags and run cdk deploy again, those new tags DO get applied to the API. It appears that this issue occurs on resource creation.

Environment

  • CLI Version : 1.67.0
  • Framework Version: 1.67.0
  • Node.js Version: 12.3.1
  • OS : Windows 10
  • Language (Version): TypeScript

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alex-a-ncinocommented, Jun 4, 2021

After further investigation, we realized the issue was the role that was deploying the CDK app didn’t have access to tag APIs. Once that’s fixed CDK is actually tagging APIs. One thing to note is that since tags were being added to the CF template re-deploy to an existing stack doesn’t see any change to tags so it doesn’t add them. So either destroy/deploy or changing the tag values for the tags to be applied. The required permission was apigateway:PUT on arn:aws:apigateway:*::/tags/*

0reactions
github-actions[bot]commented, Jun 11, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tagging your API Gateway resources - AWS Documentation
Like tag keys, tag values are case-sensitive. Tags help you do the following: Control access to your resources based on the tags that...
Read more >
@aws-cdk/aws-apigateway | Yarn - Package Manager
Amazon API Gateway is a fully managed service that makes it easy for developers to publish, maintain, monitor, and secure APIs at any...
Read more >
Create and attach an API Gateway resource policy to an API
To update an API Gateway resource policy, you'll need to have apigateway:UpdateRestApiPolicy permission in addition to apigateway:PATCH permission. The resource ...
Read more >
Ask Question - Stack Overflow
How to do lambda integrations for API Gateways defined with AWS CDK SpecRestApi and swagger.yml/openapi · Ask Question. Asked 8 months ago.
Read more >
@aws-cdk/aws-apigateway - npm
You can use Amazon API Gateway with AWS Step Functions as the backend integration, specifically Synchronous Express Workflows. The StepFunctionsRestApi only ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found