# BasicStepScalingPolicyProps

Used as argument in: [IAutoScalingGroup.scaleOnMetric](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.IAutoScalingGroup.html#scaleonmetric)

- Source: [`aws-autoscaling/lib/step-scaling-policy.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-autoscaling/lib/step-scaling-policy.ts#L10)
- Type last changed: v2.123.0 · 24 Jan 2024

## Example

TypeScript:

```ts
declare const autoScalingGroup: autoscaling.AutoScalingGroup;

const workerUtilizationMetric = new cloudwatch.Metric({
    namespace: 'MyService',
    metricName: 'WorkerUtilization'
});

autoScalingGroup.scaleOnMetric('ScaleToCPU', {
  metric: workerUtilizationMetric,
  scalingSteps: [
    { upper: 10, change: -1 },
    { lower: 50, change: +1 },
    { lower: 70, change: +3 },
  ],
  evaluationPeriods: 10,
  datapointsToAlarm: 5,

  // Change this to AdjustmentType.PERCENT_CHANGE_IN_CAPACITY to interpret the
  // 'change' numbers before as percentages instead of capacity counts.
  adjustmentType: autoscaling.AdjustmentType.CHANGE_IN_CAPACITY,
});
```

Python:

```python
# auto_scaling_group: autoscaling.AutoScalingGroup

worker_utilization_metric = cloudwatch.Metric(
    namespace="MyService",
    metric_name="WorkerUtilization"
)

auto_scaling_group.scale_on_metric("ScaleToCPU",
    metric=worker_utilization_metric,
    scaling_steps=[autoscaling.ScalingInterval(upper=10, change=-1), autoscaling.ScalingInterval(lower=50, change=+1), autoscaling.ScalingInterval(lower=70, change=+3)
    ],
    evaluation_periods=10,
    datapoints_to_alarm=5,

    # Change this to AdjustmentType.PERCENT_CHANGE_IN_CAPACITY to interpret the
    # 'change' numbers before as percentages instead of capacity counts.
    adjustment_type=autoscaling.AdjustmentType.CHANGE_IN_CAPACITY
)
```

Java:

```java
AutoScalingGroup autoScalingGroup;

Metric workerUtilizationMetric = Metric.Builder.create()
        .namespace("MyService")
        .metricName("WorkerUtilization")
        .build();

autoScalingGroup.scaleOnMetric("ScaleToCPU", BasicStepScalingPolicyProps.builder()
        .metric(workerUtilizationMetric)
        .scalingSteps(List.of(ScalingInterval.builder().upper(10).change(-1).build(), ScalingInterval.builder().lower(50).change(+1).build(), ScalingInterval.builder().lower(70).change(+3).build()))
        .evaluationPeriods(10)
        .datapointsToAlarm(5)

        // Change this to AdjustmentType.PERCENT_CHANGE_IN_CAPACITY to interpret the
        // 'change' numbers before as percentages instead of capacity counts.
        .adjustmentType(AdjustmentType.CHANGE_IN_CAPACITY)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
AutoScalingGroup autoScalingGroup;

var workerUtilizationMetric = new Metric(new MetricProps {
    Namespace = "MyService",
    MetricName = "WorkerUtilization"
});

autoScalingGroup.ScaleOnMetric("ScaleToCPU", new BasicStepScalingPolicyProps {
    Metric = workerUtilizationMetric,
    ScalingSteps = new [] { new ScalingInterval { Upper = 10, Change = -1 }, new ScalingInterval { Lower = 50, Change = +1 }, new ScalingInterval { Lower = 70, Change = +3 } },
    EvaluationPeriods = 10,
    DatapointsToAlarm = 5,

    // Change this to AdjustmentType.PERCENT_CHANGE_IN_CAPACITY to interpret the
    // 'change' numbers before as percentages instead of capacity counts.
    AdjustmentType = AdjustmentType.CHANGE_IN_CAPACITY
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var autoScalingGroup AutoScalingGroup

workerUtilizationMetric := cloudwatch.NewMetric(&MetricProps{
	Namespace: jsii.String("MyService"),
	MetricName: jsii.String("WorkerUtilization"),
})

autoScalingGroup.scaleOnMetric(jsii.String("ScaleToCPU"), &BasicStepScalingPolicyProps{
	Metric: workerUtilizationMetric,
	ScalingSteps: []ScalingInterval{
		&ScalingInterval{
			Upper: jsii.Number(10),
			Change: -jsii.Number(1),
		},
		&ScalingInterval{
			Lower: jsii.Number(50),
			Change: +jsii.Number(1),
		},
		&ScalingInterval{
			Lower: jsii.Number(70),
			Change: +jsii.Number(3),
		},
	},
	EvaluationPeriods: jsii.Number(10),
	DatapointsToAlarm: jsii.Number(5),

	// Change this to AdjustmentType.PERCENT_CHANGE_IN_CAPACITY to interpret the
	// 'change' numbers before as percentages instead of capacity counts.
	AdjustmentType: autoscaling.AdjustmentType_CHANGE_IN_CAPACITY,
})
```

## Properties

- `adjustmentType`: [AdjustmentType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.AdjustmentType.html) = ChangeInCapacity — How the adjustment numbers inside 'intervals' are interpreted.

- `cooldown`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — Grace period after scaling activity.

  **Default:** Default cooldown period on your AutoScalingGroup

- `datapointsToAlarm`: number — The number of data points out of the evaluation periods that must be breaching to trigger a scaling action.

  **Default:** Same as `evaluationPeriods`

  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`. Must be less than or equal to
  `evaluationPeriods`.

- `estimatedInstanceWarmup`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — Estimated time until a newly launched instance can send metrics to CloudWatch.

  **Default:** Same as the cooldown

- `evaluationPeriods`: number = 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.

- `metric`: [IMetric](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.IMetric.html) (required) — Metric to scale on.

- `metricAggregationType`: [MetricAggregationType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.MetricAggregationType.html) — Aggregation to apply to all data points over the evaluation periods.

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

  Only has meaning if `evaluationPeriods != 1`.

- `minAdjustmentMagnitude`: number — Minimum absolute number to adjust capacity with as result of percentage scaling.

  **Default:** No minimum scaling effect

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

- `scalingSteps`: [ScalingInterval](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.ScalingInterval.html)[] (required) — The intervals for scaling.

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

  Must be between 2 and 40 steps.
