Skip to content

Commit

Permalink
Fix Step Scaling implementation to add ScalingTargetId and default Ad…
Browse files Browse the repository at this point in the history
…justmentType
  • Loading branch information
piradeepk committed May 10, 2019
1 parent 145da28 commit 0791f27
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class StepScalingAction extends cdk.Construct implements cloudwatch.IAlar
const resource = new CfnScalingPolicy(this, 'Resource', {
policyName: props.policyName || this.node.uniqueId,
policyType: 'StepScaling',
scalingTargetId: props.scalingTarget.scalableTargetId,
stepScalingPolicyConfiguration: {
adjustmentType: props.adjustmentType,
cooldown: props.cooldownSec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class StepScalingPolicy extends cdk.Construct {
const threshold = intervals[alarms.lowerAlarmIntervalIndex].upper;

this.lowerAction = new StepScalingAction(this, 'LowerPolicy', {
adjustmentType: props.adjustmentType,
adjustmentType,
cooldownSec: props.cooldownSec,
metricAggregationType: aggregationTypeFromMetric(props.metric),
minAdjustmentMagnitude: props.minAdjustmentMagnitude,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { SynthUtils } from '@aws-cdk/assert';
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
import cdk = require('@aws-cdk/cdk');
Expand Down Expand Up @@ -116,6 +117,43 @@ export = {

test.done();
},

'test step scaling on metric'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const target = createScalableTarget(stack);

// WHEN
target.scaleOnMetric('Tracking', {
metric: new cloudwatch.Metric({ namespace: 'Test', metricName: 'Metric' }),
scalingSteps: [
{ upper: 0, change: -1 },
{ lower: 100, change: +1 },
{ lower: 500, change: +5 }
]
});

// THEN
expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalingPolicy', {
PolicyType: "StepScaling",
ScalingTargetId: {
Ref: "Target3191CF44"
},
StepScalingPolicyConfiguration: {
AdjustmentType: "ChangeInCapacity",
MetricAggregationType: "Average",
StepAdjustments: [
{
MetricIntervalUpperBound: 0,
ScalingAdjustment: -1
}
]
}

}));

test.done();
}
};

/**
Expand Down

0 comments on commit 0791f27

Please sign in to comment.