# 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.

Extends: Construct › StepScalingPolicy
Implements: IConstruct, IDependable

- Source: [`aws-applicationautoscaling/lib/step-scaling-policy.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-applicationautoscaling/lib/step-scaling-policy.ts#L105)

## 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,
});
```

## Initializer

```ts
new StepScalingPolicy(scope: Construct, id: string, props: StepScalingPolicyProps)
```

## Construct Props

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

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

  **Default:** No cooldown period

  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.

- `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`.

- `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](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.IMetric.html) (required) — Metric to scale on.

- `metricAggregationType`: [MetricAggregationType](/cdk/api/v2/docs/aws-cdk-lib.aws_applicationautoscaling.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](/cdk/api/v2/docs/aws-cdk-lib.aws_applicationautoscaling.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.

- `scalingTarget`: [IScalableTargetRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_applicationautoscaling.IScalableTargetRef.html) (required) — The scaling target.

## Properties

- `lowerAction`: [StepScalingAction](/cdk/api/v2/docs/aws-cdk-lib.aws_applicationautoscaling.StepScalingAction.html)

- `lowerAlarm`: [Alarm](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.Alarm.html)

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `upperAction`: [StepScalingAction](/cdk/api/v2/docs/aws-cdk-lib.aws_applicationautoscaling.StepScalingAction.html)

- `upperAlarm`: [Alarm](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.Alarm.html)

## Methods

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  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**

  - `x` — Any object.

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

- `toString(): string` — Returns a string representation of this construct.

- `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.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
