Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(scope: cdk.Construct, id: string, props: StepScalingPolicyProps) {
super(scope, id);
if (props.scalingSteps.length < 2) {
throw new Error('You must supply at least 2 intervals for autoscaling');
}
const adjustmentType = props.adjustmentType || AdjustmentType.CHANGE_IN_CAPACITY;
const changesAreAbsolute = adjustmentType === AdjustmentType.EXACT_CAPACITY;
const intervals = normalizeIntervals(props.scalingSteps, changesAreAbsolute);
const alarms = findAlarmThresholds(intervals);
if (alarms.lowerAlarmIntervalIndex !== undefined) {
const threshold = intervals[alarms.lowerAlarmIntervalIndex].upper;
this.lowerAction = new StepScalingAction(this, 'LowerPolicy', {
adjustmentType,
cooldown: props.cooldown,
metricAggregationType: aggregationTypeFromMetric(props.metric),
minAdjustmentMagnitude: props.minAdjustmentMagnitude,
scalingTarget: props.scalingTarget,
});
for (let i = alarms.lowerAlarmIntervalIndex; i >= 0; i--) {
this.lowerAction.addAdjustment({
adjustment: intervals[i].change!,
lowerBound: i !== 0 ? intervals[i].lower - threshold : undefined, // Extend last interval to -infinity
constructor(scope: cdk.Construct, id: string, props: StepScalingPolicyProps) {
super(scope, id);
if (props.scalingSteps.length < 2) {
throw new Error('You must supply at least 2 intervals for autoscaling');
}
const adjustmentType = props.adjustmentType || AdjustmentType.CHANGE_IN_CAPACITY;
const changesAreAbsolute = adjustmentType === AdjustmentType.EXACT_CAPACITY;
const intervals = normalizeIntervals(props.scalingSteps, changesAreAbsolute);
const alarms = findAlarmThresholds(intervals);
if (alarms.lowerAlarmIntervalIndex !== undefined) {
const threshold = intervals[alarms.lowerAlarmIntervalIndex].upper;
this.lowerAction = new StepScalingAction(this, 'LowerPolicy', {
adjustmentType: props.adjustmentType,
cooldown: props.cooldown,
metricAggregationType: aggregationTypeFromMetric(props.metric),
minAdjustmentMagnitude: props.minAdjustmentMagnitude,
autoScalingGroup: props.autoScalingGroup,
});
for (let i = alarms.lowerAlarmIntervalIndex; i >= 0; i--) {
this.lowerAction.addAdjustment({
adjustment: intervals[i].change!,
lowerBound: i !== 0 ? intervals[i].lower - threshold : undefined, // Extend last interval to -infinity