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
- fix(aws-cloudwatch): metric id should be started with a lowercase letter fixes #13434 — committed to BLasan/aws-cdk by BLasan 3 years ago
- fix(aws-cloudwatch): metric id should be started with a lowercase letter fixes #13434 — committed to BLasan/aws-cdk by BLasan 3 years ago
- fix(aws-cloudwatch): metric id should be started with a lowercase letter fixes #13434 — committed to BLasan/aws-cdk by BLasan 3 years ago
- fix(aws-cloudwatch): metric id should be started with a lowercase letter fixes #13434 — committed to BLasan/aws-cdk by BLasan 3 years ago
- fix(cloudwatch): cannot create Alarms from labeled metrics that start with a digit (#13560) fixes #13434 ---- *By submitting this pull request, I confirm that my contribution is made under th... — committed to aws/aws-cdk by BLasan 3 years ago
- chore(deps-dev): bump aws-cdk from 1.93.0 to 1.94.1 (#171) Bumps [aws-cdk](https://github.com/aws/aws-cdk/tree/HEAD/packages/aws-cdk) from 1.93.0 to 1.94.1. <details> <summary>Release notes</summary>... — committed to nikovirtala/cdk-preview-environments by dependabot[bot] 3 years ago
- build(deps-dev): bump aws-cdk from 1.93.0 to 1.94.1 (#190) Bumps [aws-cdk](https://github.com/aws/aws-cdk/tree/HEAD/packages/aws-cdk) from 1.93.0 to 1.94.1. <details> <summary>Release notes</summary>... — committed to trexcoe/smile-jenkins by mergify[bot] 3 years ago
- chore(deps): bump @aws-cdk/aws-ec2 from 1.93.0 to 1.94.1 (#72) Bumps [@aws-cdk/aws-ec2](https://github.com/aws/aws-cdk/tree/HEAD/packages/@aws-cdk/aws-ec2) from 1.93.0 to 1.94.1. <details> <summary>R... — committed to wchaws/effective-cdk by mergify[bot] 3 years ago
- build(deps-dev): bump aws-cdk from 1.93.0 to 1.94.1 (#13) Bumps [aws-cdk](https://github.com/aws/aws-cdk/tree/HEAD/packages/aws-cdk) from 1.93.0 to 1.94.1. <details> <summary>Release notes</summary> ... — committed to nikovirtala/cdk-eks-experiment by dependabot[bot] 3 years ago
- build(deps-dev): bump aws-cdk from 1.93.0 to 1.94.1 (#12) Bumps [aws-cdk](https://github.com/aws/aws-cdk/tree/HEAD/packages/aws-cdk) from 1.93.0 to 1.94.1. <details> <summary>Release notes</summary> ... — committed to wheatstalk/oidc-mock by dependabot[bot] 3 years ago
- chore(deps): bump @aws-cdk-containers/ecs-service-extensions from 1.93.0 to 1.94.1 (#173) [//]: # (dependabot-start) ⚠️ **Dependabot is rebasing this PR** ⚠️ If you make any changes to it yourself... — committed to nikovirtala/cdk-preview-environments by dependabot[bot] 3 years ago
- build(deps): bump @aws-cdk/core from 1.93.0 to 1.94.1 (#191) [//]: # (dependabot-start) ⚠️ **Dependabot is rebasing this PR** ⚠️ If you make any changes to it yourself then they will take preceden... — committed to trexcoe/smile-jenkins by mergify[bot] 3 years ago
- chore(deps): bump @aws-cdk/aws-lambda from 1.93.0 to 1.94.1 (#76) [//]: # (dependabot-start) ⚠️ **Dependabot is rebasing this PR** ⚠️ If you make any changes to it yourself then they will take pre... — committed to wchaws/effective-cdk by mergify[bot] 3 years ago
- chore(deps-dev): bump aws-cdk from 1.93.0 to 1.94.1 (#73) [//]: # (dependabot-start) ⚠️ **Dependabot is rebasing this PR** ⚠️ If you make any changes to it yourself then they will take precedence ... — committed to wchaws/effective-cdk by mergify[bot] 3 years ago
- chore(deps): bump @aws-cdk/assert from 1.93.0 to 1.94.1 (#74) [//]: # (dependabot-start) ⚠️ **Dependabot is rebasing this PR** ⚠️ If you make any changes to it yourself then they will take precede... — committed to wchaws/effective-cdk by mergify[bot] 3 years ago
- chore(deps): bump @aws-cdk/assert from 1.93.0 to 1.94.1 (#174) Bumps [@aws-cdk/assert](https://github.com/aws/aws-cdk/tree/HEAD/packages/@aws-cdk/assert) from 1.93.0 to 1.94.1. <details> <summary>Rel... — committed to nikovirtala/cdk-preview-environments by dependabot[bot] 3 years ago
- build(deps): bump @aws-cdk/assert from 1.93.0 to 1.94.1 (#192) Bumps [@aws-cdk/assert](https://github.com/aws/aws-cdk/tree/HEAD/packages/@aws-cdk/assert) from 1.93.0 to 1.94.1. <details> <summary>Rel... — committed to trexcoe/smile-jenkins by mergify[bot] 3 years ago
Sure, go ahead…
It’s just all about the CloudFormation specification and how the cdk creates underlying resources.
ID property: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudwatch-alarm-metricdataquery.html#cfn-cloudwatch-alarm-metricdataquery-id
Metrics property on alarm: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarm-metrics
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