aws-cdk-lib.aws_autoscaling.CfnScalingPolicy

class CfnScalingPolicy (construct)

LanguageType name
.NETAmazon.CDK.AWS.AutoScaling.CfnScalingPolicy
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsautoscaling#CfnScalingPolicy
Javasoftware.amazon.awscdk.services.autoscaling.CfnScalingPolicy
Pythonaws_cdk.aws_autoscaling.CfnScalingPolicy
TypeScript aws-cdk-lib » aws_autoscaling » CfnScalingPolicy

Implements IConstruct, IDependable, IInspectable

A CloudFormation AWS::AutoScaling::ScalingPolicy.

The AWS::AutoScaling::ScalingPolicy resource specifies an Amazon EC2 Auto Scaling scaling policy so that the Auto Scaling group can scale the number of instances available for your application.

For more information about using scaling policies to scale your Auto Scaling group automatically, see Dynamic scaling and Predictive scaling in the Amazon EC2 Auto Scaling User Guide .

Example

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_autoscaling as autoscaling } from 'aws-cdk-lib';
const cfnScalingPolicy = new autoscaling.CfnScalingPolicy(this, 'MyCfnScalingPolicy', {
  autoScalingGroupName: 'autoScalingGroupName',

  // the properties below are optional
  adjustmentType: 'adjustmentType',
  cooldown: 'cooldown',
  estimatedInstanceWarmup: 123,
  metricAggregationType: 'metricAggregationType',
  minAdjustmentMagnitude: 123,
  policyType: 'policyType',
  predictiveScalingConfiguration: {
    metricSpecifications: [{
      targetValue: 123,

      // the properties below are optional
      customizedCapacityMetricSpecification: {
        metricDataQueries: [{
          id: 'id',

          // the properties below are optional
          expression: 'expression',
          label: 'label',
          metricStat: {
            metric: {
              metricName: 'metricName',
              namespace: 'namespace',

              // the properties below are optional
              dimensions: [{
                name: 'name',
                value: 'value',
              }],
            },
            stat: 'stat',

            // the properties below are optional
            unit: 'unit',
          },
          returnData: false,
        }],
      },
      customizedLoadMetricSpecification: {
        metricDataQueries: [{
          id: 'id',

          // the properties below are optional
          expression: 'expression',
          label: 'label',
          metricStat: {
            metric: {
              metricName: 'metricName',
              namespace: 'namespace',

              // the properties below are optional
              dimensions: [{
                name: 'name',
                value: 'value',
              }],
            },
            stat: 'stat',

            // the properties below are optional
            unit: 'unit',
          },
          returnData: false,
        }],
      },
      customizedScalingMetricSpecification: {
        metricDataQueries: [{
          id: 'id',

          // the properties below are optional
          expression: 'expression',
          label: 'label',
          metricStat: {
            metric: {
              metricName: 'metricName',
              namespace: 'namespace',

              // the properties below are optional
              dimensions: [{
                name: 'name',
                value: 'value',
              }],
            },
            stat: 'stat',

            // the properties below are optional
            unit: 'unit',
          },
          returnData: false,
        }],
      },
      predefinedLoadMetricSpecification: {
        predefinedMetricType: 'predefinedMetricType',

        // the properties below are optional
        resourceLabel: 'resourceLabel',
      },
      predefinedMetricPairSpecification: {
        predefinedMetricType: 'predefinedMetricType',

        // the properties below are optional
        resourceLabel: 'resourceLabel',
      },
      predefinedScalingMetricSpecification: {
        predefinedMetricType: 'predefinedMetricType',

        // the properties below are optional
        resourceLabel: 'resourceLabel',
      },
    }],

    // the properties below are optional
    maxCapacityBreachBehavior: 'maxCapacityBreachBehavior',
    maxCapacityBuffer: 123,
    mode: 'mode',
    schedulingBufferTime: 123,
  },
  scalingAdjustment: 123,
  stepAdjustments: [{
    scalingAdjustment: 123,

    // the properties below are optional
    metricIntervalLowerBound: 123,
    metricIntervalUpperBound: 123,
  }],
  targetTrackingConfiguration: {
    targetValue: 123,

    // the properties below are optional
    customizedMetricSpecification: {
      metricName: 'metricName',
      namespace: 'namespace',
      statistic: 'statistic',

      // the properties below are optional
      dimensions: [{
        name: 'name',
        value: 'value',
      }],
      unit: 'unit',
    },
    disableScaleIn: false,
    predefinedMetricSpecification: {
      predefinedMetricType: 'predefinedMetricType',

      // the properties below are optional
      resourceLabel: 'resourceLabel',
    },
  },
});

Initializer

new CfnScalingPolicy(scope: Construct, id: string, props: CfnScalingPolicyProps)

Parameters

  • scope Construct — - scope in which this resource is defined.
  • id string — - scoped id of the resource.
  • props CfnScalingPolicyProps — - resource properties.

Create a new AWS::AutoScaling::ScalingPolicy.

Construct Props

NameTypeDescription
autoScalingGroupNamestringThe name of the Auto Scaling group.
adjustmentType?stringSpecifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage).
cooldown?stringA cooldown period, in seconds, that applies to a specific simple scaling policy.
estimatedInstanceWarmup?numberNot needed if the default instance warmup is defined for the group..
metricAggregationType?stringThe aggregation type for the CloudWatch metrics.
minAdjustmentMagnitude?numberThe minimum value to scale by when the adjustment type is PercentChangeInCapacity .
policyType?stringOne of the following policy types:.
predictiveScalingConfiguration?IResolvable | PredictiveScalingConfigurationPropertyA predictive scaling policy. Provides support for predefined and custom metrics.
scalingAdjustment?numberThe amount by which to scale, based on the specified adjustment type.
stepAdjustments?IResolvable | IResolvable | StepAdjustmentProperty[]A set of adjustments that enable you to scale based on the size of the alarm breach.
targetTrackingConfiguration?IResolvable | TargetTrackingConfigurationPropertyA target tracking scaling policy. Provides support for predefined or custom metrics.

autoScalingGroupName

Type: string

The name of the Auto Scaling group.


adjustmentType?

Type: string (optional)

Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage).

The valid values are ChangeInCapacity , ExactCapacity , and PercentChangeInCapacity .

Required if the policy type is StepScaling or SimpleScaling . For more information, see Scaling adjustment types in the Amazon EC2 Auto Scaling User Guide .


cooldown?

Type: string (optional)

A cooldown period, in seconds, that applies to a specific simple scaling policy.

When a cooldown period is specified here, it overrides the default cooldown.

Valid only if the policy type is SimpleScaling . For more information, see Scaling cooldowns for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide .

Default: None


estimatedInstanceWarmup?

Type: number (optional)

Not needed if the default instance warmup is defined for the group..

The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics. This warm-up period applies to instances launched due to a specific target tracking or step scaling policy. When a warm-up period is specified here, it overrides the default instance warmup.

Valid only if the policy type is TargetTrackingScaling or StepScaling .

The default is to use the value for the default instance warmup defined for the group. If default instance warmup is null, then EstimatedInstanceWarmup falls back to the value of default cooldown.


metricAggregationType?

Type: string (optional)

The aggregation type for the CloudWatch metrics.

The valid values are Minimum , Maximum , and Average . If the aggregation type is null, the value is treated as Average .

Valid only if the policy type is StepScaling .


minAdjustmentMagnitude?

Type: number (optional)

The minimum value to scale by when the adjustment type is PercentChangeInCapacity .

For example, suppose that you create a step scaling policy to scale out an Auto Scaling group by 25 percent and you specify a MinAdjustmentMagnitude of 2. If the group has 4 instances and the scaling policy is performed, 25 percent of 4 is 1. However, because you specified a MinAdjustmentMagnitude of 2, Amazon EC2 Auto Scaling scales out the group by 2 instances.

Valid only if the policy type is StepScaling or SimpleScaling . For more information, see Scaling adjustment types in the Amazon EC2 Auto Scaling User Guide .

Some Auto Scaling groups use instance weights. In this case, set the MinAdjustmentMagnitude to a value that is at least as large as your largest instance weight.


policyType?

Type: string (optional)

One of the following policy types:.

  • TargetTrackingScaling
  • StepScaling
  • SimpleScaling (default)
  • PredictiveScaling

predictiveScalingConfiguration?

Type: IResolvable | PredictiveScalingConfigurationProperty (optional)

A predictive scaling policy. Provides support for predefined and custom metrics.

Predefined metrics include CPU utilization, network in/out, and the Application Load Balancer request count.

Required if the policy type is PredictiveScaling .


scalingAdjustment?

Type: number (optional)

The amount by which to scale, based on the specified adjustment type.

A positive value adds to the current capacity while a negative number removes from the current capacity. For exact capacity, you must specify a non-negative value.

Required if the policy type is SimpleScaling . (Not used with any other policy type.)


stepAdjustments?

Type: IResolvable | IResolvable | StepAdjustmentProperty[] (optional)

A set of adjustments that enable you to scale based on the size of the alarm breach.

Required if the policy type is StepScaling . (Not used with any other policy type.)


targetTrackingConfiguration?

Type: IResolvable | TargetTrackingConfigurationProperty (optional)

A target tracking scaling policy. Provides support for predefined or custom metrics.

The following predefined metrics are available:

  • ASGAverageCPUUtilization
  • ASGAverageNetworkIn
  • ASGAverageNetworkOut
  • ALBRequestCountPerTarget

If you specify ALBRequestCountPerTarget for the metric, you must specify the ResourceLabel property with the PredefinedMetricSpecification .

Required if the policy type is TargetTrackingScaling .

Properties

NameTypeDescription
attrArnstring
attrPolicyNamestringReturns the name of a scaling policy.
autoScalingGroupNamestringThe name of the Auto Scaling group.
cfnOptionsICfnResourceOptionsOptions for this resource, such as condition, update policy etc.
cfnProperties{ [string]: any }
cfnResourceTypestringAWS resource type.
creationStackstring[]
logicalIdstringThe logical ID for this CloudFormation stack element.
nodeNodeThe tree node.
refstringReturn a string that will be resolved to a CloudFormation { Ref } for this element.
stackStackThe stack in which this element is defined.
adjustmentType?stringSpecifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage).
cooldown?stringA cooldown period, in seconds, that applies to a specific simple scaling policy.
estimatedInstanceWarmup?numberNot needed if the default instance warmup is defined for the group..
metricAggregationType?stringThe aggregation type for the CloudWatch metrics.
minAdjustmentMagnitude?numberThe minimum value to scale by when the adjustment type is PercentChangeInCapacity .
policyType?stringOne of the following policy types:.
predictiveScalingConfiguration?IResolvable | PredictiveScalingConfigurationPropertyA predictive scaling policy. Provides support for predefined and custom metrics.
scalingAdjustment?numberThe amount by which to scale, based on the specified adjustment type.
stepAdjustments?IResolvable | IResolvable | StepAdjustmentProperty[]A set of adjustments that enable you to scale based on the size of the alarm breach.
targetTrackingConfiguration?IResolvable | TargetTrackingConfigurationPropertyA target tracking scaling policy. Provides support for predefined or custom metrics.
static CFN_RESOURCE_TYPE_NAMEstringThe CloudFormation resource type name for this resource class.

attrArn

Type: string


attrPolicyName

Type: string

Returns the name of a scaling policy.


autoScalingGroupName

Type: string

The name of the Auto Scaling group.


cfnOptions

Type: ICfnResourceOptions

Options for this resource, such as condition, update policy etc.


cfnProperties

Type: { [string]: any }


cfnResourceType

Type: string

AWS resource type.


creationStack

Type: string[]


logicalId

Type: string

The logical ID for this CloudFormation stack element.

The logical ID of the element is calculated from the path of the resource node in the construct tree.

To override this value, use overrideLogicalId(newLogicalId).


node

Type: Node

The tree node.


ref

Type: string

Return a string that will be resolved to a CloudFormation { Ref } for this element.

If, by any chance, the intrinsic reference of a resource is not a string, you could coerce it to an IResolvable through Lazy.any({ produce: resource.ref }).


stack

Type: Stack

The stack in which this element is defined.

CfnElements must be defined within a stack scope (directly or indirectly).


adjustmentType?

Type: string (optional)

Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage).

The valid values are ChangeInCapacity , ExactCapacity , and PercentChangeInCapacity .

Required if the policy type is StepScaling or SimpleScaling . For more information, see Scaling adjustment types in the Amazon EC2 Auto Scaling User Guide .


cooldown?

Type: string (optional)

A cooldown period, in seconds, that applies to a specific simple scaling policy.

When a cooldown period is specified here, it overrides the default cooldown.

Valid only if the policy type is SimpleScaling . For more information, see Scaling cooldowns for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide .

Default: None


estimatedInstanceWarmup?

Type: number (optional)

Not needed if the default instance warmup is defined for the group..

The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics. This warm-up period applies to instances launched due to a specific target tracking or step scaling policy. When a warm-up period is specified here, it overrides the default instance warmup.

Valid only if the policy type is TargetTrackingScaling or StepScaling .

The default is to use the value for the default instance warmup defined for the group. If default instance warmup is null, then EstimatedInstanceWarmup falls back to the value of default cooldown.


metricAggregationType?

Type: string (optional)

The aggregation type for the CloudWatch metrics.

The valid values are Minimum , Maximum , and Average . If the aggregation type is null, the value is treated as Average .

Valid only if the policy type is StepScaling .


minAdjustmentMagnitude?

Type: number (optional)

The minimum value to scale by when the adjustment type is PercentChangeInCapacity .

For example, suppose that you create a step scaling policy to scale out an Auto Scaling group by 25 percent and you specify a MinAdjustmentMagnitude of 2. If the group has 4 instances and the scaling policy is performed, 25 percent of 4 is 1. However, because you specified a MinAdjustmentMagnitude of 2, Amazon EC2 Auto Scaling scales out the group by 2 instances.

Valid only if the policy type is StepScaling or SimpleScaling . For more information, see Scaling adjustment types in the Amazon EC2 Auto Scaling User Guide .

Some Auto Scaling groups use instance weights. In this case, set the MinAdjustmentMagnitude to a value that is at least as large as your largest instance weight.


policyType?

Type: string (optional)

One of the following policy types:.

  • TargetTrackingScaling
  • StepScaling
  • SimpleScaling (default)
  • PredictiveScaling

predictiveScalingConfiguration?

Type: IResolvable | PredictiveScalingConfigurationProperty (optional)

A predictive scaling policy. Provides support for predefined and custom metrics.

Predefined metrics include CPU utilization, network in/out, and the Application Load Balancer request count.

Required if the policy type is PredictiveScaling .


scalingAdjustment?

Type: number (optional)

The amount by which to scale, based on the specified adjustment type.

A positive value adds to the current capacity while a negative number removes from the current capacity. For exact capacity, you must specify a non-negative value.

Required if the policy type is SimpleScaling . (Not used with any other policy type.)


stepAdjustments?

Type: IResolvable | IResolvable | StepAdjustmentProperty[] (optional)

A set of adjustments that enable you to scale based on the size of the alarm breach.

Required if the policy type is StepScaling . (Not used with any other policy type.)


targetTrackingConfiguration?

Type: IResolvable | TargetTrackingConfigurationProperty (optional)

A target tracking scaling policy. Provides support for predefined or custom metrics.

The following predefined metrics are available:

  • ASGAverageCPUUtilization
  • ASGAverageNetworkIn
  • ASGAverageNetworkOut
  • ALBRequestCountPerTarget

If you specify ALBRequestCountPerTarget for the metric, you must specify the ResourceLabel property with the PredefinedMetricSpecification .

Required if the policy type is TargetTrackingScaling .


static CFN_RESOURCE_TYPE_NAME

Type: string

The CloudFormation resource type name for this resource class.

Methods

NameDescription
addDeletionOverride(path)Syntactic sugar for addOverride(path, undefined).
addDependency(target)Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
addDependsOn(target)⚠️Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.
addMetadata(key, value)Add a value to the CloudFormation Resource Metadata.
addOverride(path, value)Adds an override to the synthesized CloudFormation resource.
addPropertyDeletionOverride(propertyPath)Adds an override that deletes the value of a property from the resource definition.
addPropertyOverride(propertyPath, value)Adds an override to a resource property.
applyRemovalPolicy(policy?, options?)Sets the deletion policy of the resource based on the removal policy specified.
getAtt(attributeName, typeHint?)Returns a token for an runtime attribute of this resource.
getMetadata(key)Retrieve a value value from the CloudFormation Resource Metadata.
inspect(inspector)Examines the CloudFormation resource and discloses attributes.
obtainDependencies()Retrieves an array of resources this resource depends on.
obtainResourceDependencies()Get a shallow copy of dependencies between this resource and other resources in the same stack.
overrideLogicalId(newLogicalId)Overrides the auto-generated logical ID with a specific ID.
removeDependency(target)Indicates that this resource no longer depends on another resource.
replaceDependency(target, newTarget)Replaces one dependency with another.
toString()Returns a string representation of this construct.
protected renderProperties(props)

addDeletionOverride(path)

public addDeletionOverride(path: string): void

Parameters

  • path string — The path of the value to delete.

Syntactic sugar for addOverride(path, undefined).


addDependency(target)

public addDependency(target: CfnResource): void

Parameters

  • target CfnResource

Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.

This can be used for resources across stacks (or nested stack) boundaries and the dependency will automatically be transferred to the relevant scope.


addDependsOn(target)⚠️

public addDependsOn(target: CfnResource): void

⚠️ Deprecated: use addDependency

Parameters

  • target CfnResource

Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned.


addMetadata(key, value)

public addMetadata(key: string, value: any): void

Parameters

  • key string
  • value any

Add a value to the CloudFormation Resource Metadata.

See also: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)


addOverride(path, value)

public addOverride(path: string, value: any): void

Parameters

  • path string — - The path of the property, you can use dot notation to override values in complex types.
  • value any — - The value.

Adds an override to the synthesized CloudFormation resource.

To add a property override, either use addPropertyOverride or prefix path with "Properties." (i.e. Properties.TopicName).

If the override is nested, separate each nested level using a dot (.) in the path parameter. If there is an array as part of the nesting, specify the index in the path.

To include a literal . in the property name, prefix with a \. In most programming languages you will need to write this as "\\." because the \ itself will need to be escaped.

For example,

cfnResource.addOverride('Properties.GlobalSecondaryIndexes.0.Projection.NonKeyAttributes', ['myattribute']);
cfnResource.addOverride('Properties.GlobalSecondaryIndexes.1.ProjectionType', 'INCLUDE');

would add the overrides

"Properties": {
  "GlobalSecondaryIndexes": [
    {
      "Projection": {
        "NonKeyAttributes": [ "myattribute" ]
        ...
      }
      ...
    },
    {
      "ProjectionType": "INCLUDE"
      ...
    },
  ]
  ...
}

The value argument to addOverride will not be processed or translated in any way. Pass raw JSON values in here with the correct capitalization for CloudFormation. If you pass CDK classes or structs, they will be rendered with lowercased key names, and CloudFormation will reject the template.


addPropertyDeletionOverride(propertyPath)

public addPropertyDeletionOverride(propertyPath: string): void

Parameters

  • propertyPath string — The path to the property.

Adds an override that deletes the value of a property from the resource definition.


addPropertyOverride(propertyPath, value)

public addPropertyOverride(propertyPath: string, value: any): void

Parameters

  • propertyPath string — The path of the property.
  • value any — The value.

Adds an override to a resource property.

Syntactic sugar for addOverride("Properties.<...>", value).


applyRemovalPolicy(policy?, options?)

public applyRemovalPolicy(policy?: RemovalPolicy, options?: RemovalPolicyOptions): void

Parameters

  • policy RemovalPolicy
  • options RemovalPolicyOptions

Sets the deletion policy of the resource based on the removal policy specified.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN). In some cases, a snapshot can be taken of the resource prior to deletion (RemovalPolicy.SNAPSHOT). A list of resources that support this policy can be found in the following link:

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html#aws-attribute-deletionpolicy-options


getAtt(attributeName, typeHint?)

public getAtt(attributeName: string, typeHint?: ResolutionTypeHint): Reference

Parameters

  • attributeName string — The name of the attribute.
  • typeHint ResolutionTypeHint

Returns

  • Reference

Returns a token for an runtime attribute of this resource.

Ideally, use generated attribute accessors (e.g. resource.arn), but this can be used for future compatibility in case there is no generated attribute.


getMetadata(key)

public getMetadata(key: string): any

Parameters

  • key string

Returns

  • any

Retrieve a value value from the CloudFormation Resource Metadata.

See also: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html

Note that this is a different set of metadata from CDK node metadata; this metadata ends up in the stack template under the resource, whereas CDK node metadata ends up in the Cloud Assembly.)


inspect(inspector)

public inspect(inspector: TreeInspector): void

Parameters

  • inspector TreeInspector — - tree inspector to collect and process attributes.

Examines the CloudFormation resource and discloses attributes.


obtainDependencies()

public obtainDependencies(): Stack &#124; CfnResource[]

Returns

  • Stack | CfnResource[]

Retrieves an array of resources this resource depends on.

This assembles dependencies on resources across stacks (including nested stacks) automatically.


obtainResourceDependencies()

public obtainResourceDependencies(): CfnResource[]

Returns

  • CfnResource[]

Get a shallow copy of dependencies between this resource and other resources in the same stack.


overrideLogicalId(newLogicalId)

public overrideLogicalId(newLogicalId: string): void

Parameters

  • newLogicalId string — The new logical ID to use for this stack element.

Overrides the auto-generated logical ID with a specific ID.


removeDependency(target)

public removeDependency(target: CfnResource): void

Parameters

  • target CfnResource

Indicates that this resource no longer depends on another resource.

This can be used for resources across stacks (including nested stacks) and the dependency will automatically be removed from the relevant scope.


replaceDependency(target, newTarget)

public replaceDependency(target: CfnResource, newTarget: CfnResource): void

Parameters

  • target CfnResource — The dependency to replace.
  • newTarget CfnResource — The new dependency to add.

Replaces one dependency with another.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


protected renderProperties(props)

protected renderProperties(props: { [string]: any }): { [string]: any }

Parameters

  • props { [string]: any }

Returns

  • { [string]: any }