-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cloudwatch: Use of EC2 action with Multiple dimension set in metric results into error #29331
Comments
Looks like this error is from: aws-cdk/packages/aws-cdk-lib/aws-cloudwatch/lib/alarm.ts Lines 265 to 275 in 8b01f45
I don't have the immediate fix off the top of my head. Making it a p1 bug. |
Maybe I'm missing some step but I cannot reproduce this issue. I ran
|
Hi @GavinZZ I can reproduce it. Check out my full cdk app. #!/usr/bin/env node
import 'source-map-support/register';
import { App, StackProps, Stack, CfnOutput, Duration,
aws_cloudwatch as cw,
aws_cloudwatch_actions as cwactions,
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class UnlinkedCdkAppStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const metric = new cw.Metric({
namespace: 'CWAgent',
metricName: 'disk_used_percent',
dimensionsMap: {
InstanceId: "instance-id",
ImageId: "ami-id",
InstanceType: "t2.micro",
path: "/",
device: "xvda1",
fstype: "xfs"
},
period: Duration.minutes(5),
statistic: "Average"
})
const sev3Alarm = new cw.Alarm(this, `DISK_USED_PERCENT_SEV3`, {
alarmName: `DISK_USED_PERCENT_SEV3`,
actionsEnabled: true,
metric: metric,
evaluationPeriods: 1,
datapointsToAlarm: 1,
threshold: 75,
comparisonOperator: cw.ComparisonOperator.GREATER_THAN_THRESHOLD,
treatMissingData: cw.TreatMissingData.BREACHING,
});
sev3Alarm.addAlarmAction(new cwactions.Ec2Action(cwactions.Ec2InstanceAction.REBOOT));
}
}
const app = new App();
const env = { region: process.env.CDK_DEFAULT_REGION, account: process.env.CDK_DEFAULT_ACCOUNT };
new UnlinkedCdkAppStack(app, 'UnlinkedCdkAppStack', { env });
% npx cdk --version |
Thanks Pahud, I can confirm that this is reproducible. Will investigate this issue. |
|
1 similar comment
|
Describe the bug
While trying to create a Custom Metric with multiple dimension, and adding EC2 action, the CDK synth fails with the error below.
The code for generating the error is as below
To resolve the issue, there are 2 ways of doing it, the first one is we comment out the other dimensions apart from instance id in the dimensions map as below.
Or we use escape hatch as below.
Expected Behavior
The expected behaviour is that it should allow to add EC2 action for the custom metrics too, as one can do using CloudWatch Console, and CloudFormation.
Current Behavior
The current behaviour is that it results into the error stated below.
Reproduction Steps
Use the below code, and run cdk synth
aws-cdk/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts
Line 249 in 9487b39
The text was updated successfully, but these errors were encountered: