aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.7k stars 3.93k forks source link

aws-cdk-lib/aws-cloudwatch: Tags don't attach to CloudWatch alarms #29759

Closed BerradaYassine closed 6 months ago

BerradaYassine commented 7 months ago

Describe the bug

https://github.com/aws/aws-cdk/issues/25489#issue-1701033601

Similarly to the closed issue above, I would like to add tags to Cloudwatch alarm through CDK. Recently AWS added support for cloud formation to add tags to Cloudwatch alarm

Expected Behavior

Tags can be added to the resource and verified on the AWS console.

Current Behavior

The tags don't attach to the resource.

Reproduction Steps

import as cdk from 'aws-cdk-lib'; import as sns from 'aws-cdk-lib/aws-sns'; import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; import { Construct } from 'constructs';

export class MyStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); const topic = new sns.Topic(this, 'Topic', { displayName: 'My SNS topic', }); const _alarm = new cloudwatch.Alarm(this, 'Alarm', { metric: topic.metricNumberOfMessagesPublished(), threshold: 10, evaluationPeriods: 1, alarmName: 'My SNS alarm', alarmDescription: 'Triggered when message count exceeds 10', comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD, }); } } and then

import * as cdk from 'aws-cdk-lib';

const env = { account: process.env.AWS_ACCOUNT_ID, region: process.env.AWS_REGION, }; const app = new cdk.App(); new MyStack(app, 'stack', { env, tags: { testTag: 'testValue', }, }); cdk.Tags.of(app).add('testTag', 'testValue');

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.136.0

Framework Version

No response

Node.js Version

v16.18.1

OS

14.4.1

Language

TypeScript

Language Version

4.8.4

Other information

No response

bdoyle0182 commented 7 months ago

It's officially in the cloud formation release notes now as well

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/ReleaseHistory.html

khushail commented 7 months ago

Thanks @BerradaYassine for requesting this. Thanks @bdoyle0182 for sharing the link. I could see that cloudformation provides needed support for L1 construct for the 'tags' props. Contributions from community are welcome !

Konosh93 commented 7 months ago

@khushail Looks like this will be fixed automatically next Monday., when the following version is deployed.

"@aws-cdk/aws-service-spec": "^0.0.63",
bdoyle0182 commented 7 months ago

Wonderful, thanks for the quick turnaround

rgoltz commented 7 months ago

Great hint, @Konosh93 / @bdoyle0182 - Now, it becomes less magic ;) I ready see the PR https://github.com/aws/aws-cdk/pull/29798 for updating the L1 CloudFormation resource definitions, which also include:

├[~] service aws-cloudwatch
│ └ resources
│    ├[~] resource AWS::CloudWatch::Alarm
│    │ ├  - tagInformation: undefined
│    │ │  + tagInformation: {"tagPropertyName":"Tags","variant":"standard"}
│    │ └ properties
│    │    └[+] Tags: Array<tag>

Now, we just need to wait for the next CDK release, which cover/include this PR. :)

jwilson-anonyome commented 7 months ago

https://github.com/aws/aws-cdk/releases/tag/v2.138.0 includes https://github.com/aws/aws-cdk/pull/29798

GavinZZ commented 6 months ago

Closing this issue as the feature request for tags now exist in L1 Construct for Cloudwatch alarms.

github-actions[bot] commented 6 months ago

⚠️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.

aws-cdk-automation commented 4 months ago

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.