aws-cdk: (Cloudwatch): Metrics with labels can't be used in alarms for API Gateway metrics

Just getting this with v1.92 (worked fine <=1.91) updating Cloudwatch alarm yields: Invalid metrics list (Service: AmazonCloudWatch; Status Code: 400; Error Code: ValidationError

Reproduction Steps

alarm = metric.create_alarm(
            self,
            id=id_alarm,
            alarm_description=kwargs['alarm_description'],
            threshold=kwargs['threshold'],
            period=core.Duration.minutes(kwargs['period_in_minutes']),
            comparison_operator=cw.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
            evaluation_periods=kwargs['evaluation_periods'],
            statistic=kwargs['statistic']
        )

these are the parameters I’m passing to it:

{
        "metric_name": "5XXError",
        "label": "HTTP 5XX",
        "statistic": "sum",
        "color": "#d62728",
        "period_in_minutes": 1,
        "alarm": {
          "alarm_description": "5XX at 1 threshold",
          "threshold": 1,
          "period_in_minutes": 5,
          "evaluation_periods": 1,
          "statistic": "sum"
        }
}

What did you expect to happen?

a Cloudwatch alarm resource created/updated

What actually happened?

UPDATE_FAILED        | AWS::CloudWatch::Alarm     |  
Invalid metrics list (Service: AmazonCloudWatch; Status Code: 400; Error Code: ValidationError;

Environment

  • CDK CLI Version : 1.92
  • Framework Version: 1.92
  • Node.js Version: 10
  • OS : amazonlinux2-x86_64-standard:1.0
  • Language (Version): Python (3.7)

Other


This is 🐛 Bug Report

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@robo-sk great catch! Since the ID doesn’t matter too much here (at least, I don’t think… hope I’m not wrong), we could just prefix the id with something like a lowercase m. Feel like submitting a PR for this? 😃

Can I work on this?

Sure, go ahead…

that temp fix worked perfectly. thank you so much! you’re a lifesaver. keep on rockin’ it !!!

I believe there is an issue introduced by recent bug fix in this file:

packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts

commit: cbcc712e0c4c44c83c7f4d1e8a544bccfa26bb56

(if there is a label, then the ID is created from the metric name, but there is a limitation for ID : “The first character must be a lowercase letter” … in this case, the metric name “5xxError” doesn’t fit… https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudwatch-alarm-metricdataquery.html

Quick fix is to remove the label for now.

Take a look here what I believe is the root cause of the problem:

https://github.com/aws/aws-cdk/commit/cbcc712e0c4c44c83c7f4d1e8a544bccfa26bb56#r47990368