Comments (4)
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.
from aws-cdk.
Maybe I'm missing some step but I cannot reproduce this issue. I ran cdk synth
using the following example as you provided
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as cw from 'aws-cdk-lib/aws-cloudwatch'
import { Ec2Action, Ec2InstanceAction } from 'aws-cdk-lib/aws-cloudwatch-actions';
export class UnlinkedCdkAppStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.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: cdk.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 Ec2Action(Ec2InstanceAction.REBOOT));
}
}
cdk synth
correct synth the code into the following template
Resources:
DISKUSEDPERCENTSEV36CE6B660:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- Fn::Join:
- ""
- - "arn:"
- Ref: AWS::Partition
- ":automate:"
- Ref: AWS::Region
- :ec2:reboot
AlarmName: DISK_USED_PERCENT_SEV3
ComparisonOperator: GreaterThanThreshold
DatapointsToAlarm: 1
Dimensions:
- Name: ImageId
Value: ami-id
- Name: InstanceId
Value: instance-id
- Name: InstanceType
Value: t2.micro
- Name: device
Value: xvda1
- Name: fstype
Value: xfs
- Name: path
Value: /
EvaluationPeriods: 1
MetricName: disk_used_percent
Namespace: CWAgent
Period: 300
Statistic: Average
Threshold: 75
TreatMissingData: breaching
Metadata:
aws:cdk:path: UnlinkedCdkAppStack/DISK_USED_PERCENT_SEV3/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/yXIPQ6DMAxA4bOwJ4ZkYEfcAA5QpU6qGoIt5acMiLu30Ol9ehaM7aFr3J41+lVHesIxF4er+q0HRql+dwXfcAzRpU2NL75xXppClpowXB6FPRUSPhWLD7Dk9mN6sB2YZslEOlUutAWY/v0C8ssPDnoAAAA=
Metadata:
aws:cdk:path: UnlinkedCdkAppStack/CDKMetadata/Default
Condition: CDKMetadataAvailable
Conditions:
CDKMetadataAvailable:
Fn::Or:
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- af-south-1
- Fn::Equals:
- Ref: AWS::Region
- ap-east-1
- Fn::Equals:
- Ref: AWS::Region
- ap-northeast-1
- Fn::Equals:
- Ref: AWS::Region
- ap-northeast-2
- Fn::Equals:
- Ref: AWS::Region
- ap-south-1
- Fn::Equals:
- Ref: AWS::Region
- ap-southeast-1
- Fn::Equals:
- Ref: AWS::Region
- ap-southeast-2
- Fn::Equals:
- Ref: AWS::Region
- ca-central-1
- Fn::Equals:
- Ref: AWS::Region
- cn-north-1
- Fn::Equals:
- Ref: AWS::Region
- cn-northwest-1
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- eu-central-1
- Fn::Equals:
- Ref: AWS::Region
- eu-north-1
- Fn::Equals:
- Ref: AWS::Region
- eu-south-1
- Fn::Equals:
- Ref: AWS::Region
- eu-west-1
- Fn::Equals:
- Ref: AWS::Region
- eu-west-2
- Fn::Equals:
- Ref: AWS::Region
- eu-west-3
- Fn::Equals:
- Ref: AWS::Region
- il-central-1
- Fn::Equals:
- Ref: AWS::Region
- me-central-1
- Fn::Equals:
- Ref: AWS::Region
- me-south-1
- Fn::Equals:
- Ref: AWS::Region
- sa-east-1
- Fn::Or:
- Fn::Equals:
- Ref: AWS::Region
- us-east-1
- Fn::Equals:
- Ref: AWS::Region
- us-east-2
- Fn::Equals:
- Ref: AWS::Region
- us-west-1
- Fn::Equals:
- Ref: AWS::Region
- us-west-2
Parameters:
BootstrapVersion:
Type: AWS::SSM::Parameter::Value<String>
Default: /cdk-bootstrap/hnb659fds/version
Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
Rules:
CheckBootstrapVersion:
Assertions:
- Assert:
Fn::Not:
- Fn::Contains:
- - "1"
- "2"
- "3"
- "4"
- "5"
- Ref: BootstrapVersion
AssertDescription: CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.
from aws-cdk.
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 });
cdk synth
returns this error:
Error: EC2 alarm actions requires an EC2 Per-Instance Metric. ({"metricStat":{"dimensions":[{"name":"ImageId","value":"ami-id"},{"name":"InstanceId","value":"instance-id"},{"name":"InstanceType","value":"t2.micro"},{"name":"device","value":"xvda1"},{"name":"fstype","value":"xfs"},{"name":"path","value":"/"}],"namespace":"CWAgent","metricName":"disk_used_percent","period":{"amount":5,"unit":{"label":"minutes","isoLabel":"M","inMillis":60000}},"statistic":"Average"},"renderingProperties":{}} does not have an 'InstanceId' dimension)
at Alarm.validateActionArn (/Users/hunhsieh/repos/xxx/node_modules/aws-cdk-lib/aws-cloudwatch/lib/alarm.js:1:5300)
at /Users/hunhsieh/repos/xxx/node_modules/aws-cdk-lib/aws-cloudwatch/lib/alarm.js:1:4982
at Array.map (<anonymous>)
at Alarm.addAlarmAction (/Users/hunhsieh/repos/xxx/node_modules/aws-cdk-lib/aws-cloudwatch/lib/alarm.js:1:4970)
at new UnlinkedCdkAppStack (/Users/hunhsieh/repos/xxx/bin/xxx.ts:41:15)
at Object.<anonymous> (/Users/hunhsieh/repos/xxx/bin/xxx.ts:47:1)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module.m._compile (/Users/hunhsieh/repos/xxx/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Object.require.extensions.<computed> [as .ts] (/Users/hunhsieh/repos/xxx/node_modules/ts-node/src/index.ts:1621:12)
Subprocess exited with error 1
% npx cdk --version
2.131.0 (build 92b912d)
from aws-cdk.
Thanks Pahud, I can confirm that this is reproducible. Will investigate this issue.
from aws-cdk.
Related Issues (20)
- eks: Amazon Linux 2023 support HOT 1
- (s3-deployment): BucketDeployment expose asset hash
- aws-ecs (all): validation should leverage typescript type system HOT 3
- appconfig: Constrain environments to a single deployment at a time HOT 5
- (opensearchservice): must configure zone awareness settings even when i am not enabling zone awareness HOT 11
- (stepfunctions-tasks): support bring your own role for Lambda created by EvaluteExpression HOT 5
- (stepfunction-tasks): eventbridge scheduler create, update schedule HOT 2
- AWS::Redshift::Cluster: Endpoint.Address not available during creation in cnf template with Fn::GetAtt HOT 4
- cloudfront: Missing origin event types in FunctionEventType HOT 2
- (aws-glue-alpha): S3 path specified in `--spark-event-logs-path` needs to end with slash HOT 2
- (aws_rds): (Add Support for RDS Oracle 19.0.0.0.ru-2024-01.rur-2024-01.r1 and 21.0.0.0.ru-2024-01.rur-2024-01.r1 in OracleEngineVersion) HOT 3
- CDK: RuntimeError: Error: The 'account' property must be a concrete value HOT 3
- rds: use DataAPI for Aurora cluster without invoking `secret.grantRead()` HOT 2
- boto3 python: async sns publish HOT 2
- Amazon OpenSearch Service: High Level Constructs for ColdStorage Options HOT 3
- Deployment fails with no actionable error feedback HOT 3
- aws cdk synth results in NEW folder under /tmp every time a command is run, which results to 100% disk space usage over time HOT 3
- (aws-kinesisfirehose-alpha): More than one processor and direct support for the cloudwatch logs decompression HOT 2
- lambda.LayerVersion: missing DNS when building a layer with docker HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-cdk.