[apigateway] Tags do not propagate to API Gateway resource when using openAPI spec (SpecRestApi)
See original GitHub issueWhen 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:
But those tags are not present on the API resource:
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:
- Created 3 years ago
- Reactions:4
- Comments:8 (3 by maintainers)
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
onarn:aws:apigateway:*::/tags/*
⚠️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.