Skip to content
v2.274.0

StepScalingPolicy ​

Define a scaling strategy which scales depending on absolute values of some metric.

You can specify the scaling behavior for various values of the metric.

Implemented using one or more CloudWatch alarms and Step Scaling Policies.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_applicationautoscaling as appscaling } from 'aws-cdk-lib';
import { aws_cloudwatch as cloudwatch } from 'aws-cdk-lib';
import { aws_applicationautoscaling as interfaces_applicationautoscaling } from 'aws-cdk-lib/interfaces';

declare const metric: cloudwatch.Metric;
declare const scalableTargetRef: interfaces_applicationautoscaling.IScalableTargetRef;
const stepScalingPolicy = new appscaling.StepScalingPolicy(this, 'MyStepScalingPolicy', {
  metric: metric,
  scalingSteps: [{
    change: 123,

    // the properties below are optional
    lower: 123,
    upper: 123,
  }],
  scalingTarget: scalableTargetRef,

  // the properties below are optional
  adjustmentType: appscaling.AdjustmentType.CHANGE_IN_CAPACITY,
  cooldown: cdk.Duration.minutes(30),
  datapointsToAlarm: 123,
  evaluationPeriods: 123,
  metricAggregationType: appscaling.MetricAggregationType.AVERAGE,
  minAdjustmentMagnitude: 123,
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_applicationautoscaling as appscaling
from aws_cdk import aws_cloudwatch as cloudwatch
from aws_cdk.interfaces import aws_applicationautoscaling as interfaces_applicationautoscaling

# metric: cloudwatch.Metric
# scalable_target_ref: interfaces_applicationautoscaling.IScalableTargetRef

step_scaling_policy = appscaling.StepScalingPolicy(self, "MyStepScalingPolicy",
    metric=metric,
    scaling_steps=[appscaling.ScalingInterval(
        change=123,

        # the properties below are optional
        lower=123,
        upper=123
    )],
    scaling_target=scalable_target_ref,

    # the properties below are optional
    adjustment_type=appscaling.AdjustmentType.CHANGE_IN_CAPACITY,
    cooldown=cdk.Duration.minutes(30),
    datapoints_to_alarm=123,
    evaluation_periods=123,
    metric_aggregation_type=appscaling.MetricAggregationType.AVERAGE,
    min_adjustment_magnitude=123
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.applicationautoscaling.*;
import software.amazon.awscdk.services.cloudwatch.*;
import software.amazon.awscdk.interfaces.applicationautoscaling.*;

Metric metric;
IScalableTargetRef scalableTargetRef;

StepScalingPolicy stepScalingPolicy = StepScalingPolicy.Builder.create(this, "MyStepScalingPolicy")
        .metric(metric)
        .scalingSteps(List.of(ScalingInterval.builder()
                .change(123)

                // the properties below are optional
                .lower(123)
                .upper(123)
                .build()))
        .scalingTarget(scalableTargetRef)

        // the properties below are optional
        .adjustmentType(AdjustmentType.CHANGE_IN_CAPACITY)
        .cooldown(Duration.minutes(30))
        .datapointsToAlarm(123)
        .evaluationPeriods(123)
        .metricAggregationType(MetricAggregationType.AVERAGE)
        .minAdjustmentMagnitude(123)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.ApplicationAutoScaling;
using Amazon.CDK.AWS.CloudWatch;
using Amazon.CDK.Interfaces.ApplicationAutoScaling;

Metric metric;
IScalableTargetRef scalableTargetRef;

var stepScalingPolicy = new StepScalingPolicy(this, "MyStepScalingPolicy", new StepScalingPolicyProps {
    Metric = metric,
    ScalingSteps = new [] { new ScalingInterval {
        Change = 123,

        // the properties below are optional
        Lower = 123,
        Upper = 123
    } },
    ScalingTarget = scalableTargetRef,

    // the properties below are optional
    AdjustmentType = AdjustmentType.CHANGE_IN_CAPACITY,
    Cooldown = Duration.Minutes(30),
    DatapointsToAlarm = 123,
    EvaluationPeriods = 123,
    MetricAggregationType = MetricAggregationType.AVERAGE,
    MinAdjustmentMagnitude = 123
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import cdk "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var metric Metric
var scalableTargetRef IScalableTargetRef

stepScalingPolicy := awscdk.Aws_applicationautoscaling.NewStepScalingPolicy(this, jsii.String("MyStepScalingPolicy"), &StepScalingPolicyProps{
	Metric: metric,
	ScalingSteps: []ScalingInterval{
		&ScalingInterval{
			Change: jsii.Number(123),

			// the properties below are optional
			Lower: jsii.Number(123),
			Upper: jsii.Number(123),
		},
	},
	ScalingTarget: scalableTargetRef,

	// the properties below are optional
	AdjustmentType: awscdk.*Aws_applicationautoscaling.AdjustmentType_CHANGE_IN_CAPACITY,
	Cooldown: cdk.Duration_Minutes(jsii.Number(30)),
	DatapointsToAlarm: jsii.Number(123),
	EvaluationPeriods: jsii.Number(123),
	MetricAggregationType: awscdk.*Aws_applicationautoscaling.MetricAggregationType_AVERAGE,
	MinAdjustmentMagnitude: jsii.Number(123),
})

Initializer ​

ts
new StepScalingPolicy(scope: Construct, id: string, props: StepScalingPolicyProps)
python
StepScalingPolicy(scope: Construct, id: str, props: StepScalingPolicyProps)
java
new StepScalingPolicy(Construct scope, String id, StepScalingPolicyProps props)
csharp
new StepScalingPolicy(Construct scope, string id, StepScalingPolicyProps props)
go
NewStepScalingPolicy(Scope Construct, Id *string, Props StepScalingPolicyProps)

Construct Props ​

adjustmentTypeAdjustmentTypeadjustment_typeAdjustmentTypeadjustmentTypeAdjustmentTypeAdjustmentTypeAdjustmentTypeAdjustmentTypeAdjustmentType= ChangeInCapacity#
How the adjustment numbers inside 'intervals' are interpreted.
cooldownDurationcooldownDurationcooldownDurationCooldownDurationCooldownDuration= No cooldown period#
Grace period after scaling activity.

Subsequent scale outs during the cooldown period are squashed so that only the biggest scale out happens.

Subsequent scale ins during the cooldown period are ignored.

datapointsToAlarmnumberdatapoints_to_alarmint | floatdatapointsToAlarmNumberDatapointsToAlarmdoubleDatapointsToAlarm*float64= Same as `evaluationPeriods`#
The number of data points out of the evaluation periods that must be breaching to trigger a scaling action.

Creates an "M out of N" alarm, where this property is the M and the value set for evaluationPeriods is the N value.

Only has meaning if evaluationPeriods != 1.

evaluationPeriodsnumberevaluation_periodsint | floatevaluationPeriodsNumberEvaluationPeriodsdoubleEvaluationPeriods*float64= 1#
How many evaluation periods of the metric to wait before triggering a scaling action.

Raising this value can be used to smooth out the metric, at the expense of slower response times.

If datapointsToAlarm is not set, then all data points in the evaluation period must meet the criteria to trigger a scaling action.

metricIMetricmetricIMetricmetricIMetricMetricIMetricMetricIMetricrequired#
Metric to scale on.
metricAggregationTypeMetricAggregationTypemetric_aggregation_typeMetricAggregationTypemetricAggregationTypeMetricAggregationTypeMetricAggregationTypeMetricAggregationTypeMetricAggregationTypeMetricAggregationType= The statistic from the metric if…#
Aggregation to apply to all data points over the evaluation periods.

Only has meaning if evaluationPeriods != 1.

default

Default: The statistic from the metric if applicable (MIN, MAX, AVERAGE), otherwise AVERAGE.

minAdjustmentMagnitudenumbermin_adjustment_magnitudeint | floatminAdjustmentMagnitudeNumberMinAdjustmentMagnitudedoubleMinAdjustmentMagnitude*float64= No minimum scaling effect#
Minimum absolute number to adjust capacity with as result of percentage scaling.

Only when using AdjustmentType = PercentChangeInCapacity, this number controls the minimum absolute effect size.

scalingStepsScalingInterval[]scaling_stepstyping.List[ScalingInterval]scalingStepsList<ScalingInterval>ScalingStepsScalingInterval[]ScalingSteps*[]ScalingIntervalrequired#
The intervals for scaling.

Maps a range of metric values to a particular scaling behavior.

Must be between 2 and 40 steps.

scalingTargetIScalableTargetRefscaling_targetIScalableTargetRefscalingTargetIScalableTargetRefScalingTargetIScalableTargetRefScalingTargetIScalableTargetRefrequired#
The scaling target.

Properties ​

lowerAlarmAlarmlower_alarmAlarmlowerAlarmAlarmLowerAlarmAlarmLowerAlarmAlarm#
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
upperAlarmAlarmupper_alarmAlarmupperAlarmAlarmUpperAlarmAlarmUpperAlarmAlarm#

Methods ​

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining