-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Workaround is available 👇
What is the problem?
When deploying an @aws-cdk/aws-cloudwatch.Alarm in regions with no support for cross-account alarms, the deployment fails with the following error:
Encountered unsupported property AccountId
This is because the change in #16007 always adds an AccountId to metrics.
Reproduction Steps
Define a CDK stack with an AWS CloudWatch Alarm and deploy it to a region that still does not have support for cross-account alarms.
What did you expect to happen?
Success
What actually happened?
Encountered unsupported property AccountId
CDK CLI Version
1.126.0
Framework Version
1.126.0
Node.js Version
N/A
OS
N/A
Language
Typescript, Python, .NET, Java, Go
Language Version
N/A
Other information
Ref: P53531109
Workaround
You can delete the AccountId property by locating the CfnResource behind the cloudwatch.Alarm construct and then calling addPropertyDeletionOverride.
Consider the following example:
const alarm = new cloudwatch.Alarm(this, 'Alarm', {
threshold: 1,
evaluationPeriods: 1,
metric: new cloudwatch.Metric({
label: 'MyMetric',
account: this.account,
namespace: 'AWS/DynamoDB',
metricName: 'ReadThrottleEvents',
dimensionsMap: {
TableName: 'MyTable'
},
statistic: 'Sum'
}),
});This is how the AWS::CloudWatch::Alarm is synthesized:
Alarm7103F465:
Type: AWS::CloudWatch::Alarm
Properties:
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: 1
Metrics:
- AccountId: "123456789012"
Id: m1
Label: MyMetric
MetricStat:
Metric:
Dimensions:
- Name: TableName
Value: MyTable
MetricName: ReadThrottleEvents
Namespace: AWS/DynamoDB
Period: 300
Stat: Sum
ReturnData: true
Threshold: 1The following code will delete the AccountId property from the metric at index 0 (Metrics.0) in the alarm:
const cfnAlarm = alarm.node.defaultChild as CfnResource;
cfnAlarm?.addPropertyDeletionOverride('Metrics.0.AccountId');