Skip to content

Commit 626e6aa

Browse files
authored
fix(applicationautoscaling): typo in DYANMODB_WRITE_CAPACITY_UTILIZATION (#18085)
Enum value `DYANMODB_WRITE_CAPACITY_UTILIZATION` in `PredefinedMetric` has a typo in `DYANMODB`. This PR deprecates this value and adds the new value `DYNAMODB_WRITE_CAPACITY_UTILIZATION`. I think we don't need to add a test case to this PR. Please add the label `pr-linter/exempt-test` if you agree. Fixes #17209. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a5a9cbd commit 626e6aa

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,20 @@ export class TargetTrackingScalingPolicy extends CoreConstruct {
136136

137137
super(scope, id);
138138

139+
// replace dummy value in DYNAMODB_WRITE_CAPACITY_UTILIZATION due to a jsii bug (https://github.com/aws/jsii/issues/2782)
140+
const predefinedMetric = props.predefinedMetric === PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION ?
141+
PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION :
142+
props.predefinedMetric;
143+
139144
const resource = new CfnScalingPolicy(this, 'Resource', {
140145
policyName: props.policyName || cdk.Names.uniqueId(this),
141146
policyType: 'TargetTrackingScaling',
142147
scalingTargetId: props.scalingTarget.scalableTargetId,
143148
targetTrackingScalingPolicyConfiguration: {
144149
customizedMetricSpecification: renderCustomMetric(props.customMetric),
145150
disableScaleIn: props.disableScaleIn,
146-
predefinedMetricSpecification: props.predefinedMetric !== undefined ? {
147-
predefinedMetricType: props.predefinedMetric,
151+
predefinedMetricSpecification: predefinedMetric !== undefined ? {
152+
predefinedMetricType: predefinedMetric,
148153
resourceLabel: props.resourceLabel,
149154
} : undefined,
150155
scaleInCooldown: props.scaleInCooldown && props.scaleInCooldown.toSeconds(),
@@ -183,9 +188,20 @@ export enum PredefinedMetric {
183188
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
184189
*/
185190
DYNAMODB_READ_CAPACITY_UTILIZATION = 'DynamoDBReadCapacityUtilization',
191+
/**
192+
* DYNAMODB_WRITE_CAPACITY_UTILIZATION
193+
*
194+
* Suffix `dummy` is necessary due to jsii bug (https://github.com/aws/jsii/issues/2782).
195+
* Duplicate values will be dropped, so this suffix is added as a workaround.
196+
* The value will be replaced when this enum is used.
197+
*
198+
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
199+
*/
200+
DYNAMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization-dummy',
186201
/**
187202
* DYANMODB_WRITE_CAPACITY_UTILIZATION
188203
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
204+
* @deprecated use `PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION`
189205
*/
190206
DYANMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization',
191207
/**

packages/@aws-cdk/aws-applicationautoscaling/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.StepScalingPolicyProps",
127127
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ECS_SERVICE_AVERAGE_CPU_UTILIZATION",
128128
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION",
129+
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION",
129130
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION",
130131
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ALB_REQUEST_COUNT_PER_TARGET",
131132
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.RDS_READER_AVERAGE_CPU_UTILIZATION",

packages/@aws-cdk/aws-applicationautoscaling/test/target-tracking.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ describe('target tracking', () => {
5353

5454
});
5555

56+
test('test setup target tracking on predefined metric for DYNAMODB_WRITE_CAPACITY_UTILIZATION', () => {
57+
// GIVEN
58+
const stack = new cdk.Stack();
59+
const target = createScalableTarget(stack);
60+
61+
// WHEN
62+
target.scaleToTrackMetric('Tracking', {
63+
predefinedMetric: appscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION,
64+
targetValue: 0.9,
65+
});
66+
67+
// THEN
68+
expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalingPolicy', {
69+
TargetTrackingScalingPolicyConfiguration: {
70+
PredefinedMetricSpecification: { PredefinedMetricType: 'DynamoDBWriteCapacityUtilization' },
71+
TargetValue: 0.9,
72+
},
73+
});
74+
});
75+
5676
test('test setup target tracking on custom metric', () => {
5777
// GIVEN
5878
const stack = new cdk.Stack();

packages/@aws-cdk/aws-dynamodb/lib/scalable-table-attribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ScalableTableAttribute extends appscaling.BaseScalableAttribute {
2525
}
2626
this.scalingPolicyCreated = true;
2727
const predefinedMetric = this.props.dimension.indexOf('ReadCapacity') === -1
28-
? appscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION
28+
? appscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION
2929
: appscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION;
3030

3131
super.doScaleToTrackMetric('Tracking', {

0 commit comments

Comments
 (0)