Skip to content
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

fix(applicationautoscaling): typo in DYANMODB_WRITE_CAPACITY_UTILIZATION #18085

Merged
merged 9 commits into from
Jan 14, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,20 @@ export class TargetTrackingScalingPolicy extends CoreConstruct {

super(scope, id);

// replace dummy value in DYNAMODB_WRITE_CAPACITY_UTILIZATION due to a jsii bug (https://github.com/aws/jsii/issues/2782)
const predefinedMetric = props.predefinedMetric === PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION ?
PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION :
props.predefinedMetric;

const resource = new CfnScalingPolicy(this, 'Resource', {
policyName: props.policyName || cdk.Names.uniqueId(this),
policyType: 'TargetTrackingScaling',
scalingTargetId: props.scalingTarget.scalableTargetId,
targetTrackingScalingPolicyConfiguration: {
customizedMetricSpecification: renderCustomMetric(props.customMetric),
disableScaleIn: props.disableScaleIn,
predefinedMetricSpecification: props.predefinedMetric !== undefined ? {
predefinedMetricType: props.predefinedMetric,
predefinedMetricSpecification: predefinedMetric !== undefined ? {
predefinedMetricType: predefinedMetric,
resourceLabel: props.resourceLabel,
} : undefined,
scaleInCooldown: props.scaleInCooldown && props.scaleInCooldown.toSeconds(),
Expand Down Expand Up @@ -183,9 +188,20 @@ export enum PredefinedMetric {
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
DYNAMODB_READ_CAPACITY_UTILIZATION = 'DynamoDBReadCapacityUtilization',
/**
* DYNAMODB_WRITE_CAPACITY_UTILIZATION
jumic marked this conversation as resolved.
Show resolved Hide resolved
*
* Suffix `dummy` is necessary due to jsii bug (https://github.com/aws/jsii/issues/2782).
* Duplicate values will be dropped, so this suffix is added as a workaround.
* The value will be replaced when this enum is used.
*
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
DYNAMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization-dummy',
/**
* DYANMODB_WRITE_CAPACITY_UTILIZATION
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
* @deprecated use `PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION`
*/
DYANMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization',
/**
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-applicationautoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.StepScalingPolicyProps",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ECS_SERVICE_AVERAGE_CPU_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ALB_REQUEST_COUNT_PER_TARGET",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.RDS_READER_AVERAGE_CPU_UTILIZATION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ describe('target tracking', () => {

});

test('test setup target tracking on predefined metric for DYNAMODB_WRITE_CAPACITY_UTILIZATION', () => {
// GIVEN
const stack = new cdk.Stack();
const target = createScalableTarget(stack);

// WHEN
target.scaleToTrackMetric('Tracking', {
predefinedMetric: appscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION,
targetValue: 0.9,
});

// THEN
expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalingPolicy', {
TargetTrackingScalingPolicyConfiguration: {
PredefinedMetricSpecification: { PredefinedMetricType: 'DynamoDBWriteCapacityUtilization' },
TargetValue: 0.9,
},
});
});

test('test setup target tracking on custom metric', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ScalableTableAttribute extends appscaling.BaseScalableAttribute {
}
this.scalingPolicyCreated = true;
const predefinedMetric = this.props.dimension.indexOf('ReadCapacity') === -1
? appscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION
? appscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION
: appscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION;

super.doScaleToTrackMetric('Tracking', {
Expand Down