class CfnScalingPolicy (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.AutoScaling.CfnScalingPolicy |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsautoscaling#CfnScalingPolicy |
![]() | software.amazon.awscdk.services.autoscaling.CfnScalingPolicy |
![]() | aws_cdk.aws_autoscaling.CfnScalingPolicy |
![]() | aws-cdk-lib » aws_autoscaling » CfnScalingPolicy |
Implements
IConstruct
, IDependable
, IInspectable
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: {
dimensions: [{
name: 'name',
value: 'value',
}],
metricName: 'metricName',
metrics: [{
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
period: 123,
unit: 'unit',
},
period: 123,
returnData: false,
}],
namespace: 'namespace',
period: 123,
statistic: 'statistic',
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
— Construct identifier for this resource (unique in its scope). - props
Cfn
— Resource properties.Scaling Policy Props
Construct Props
Name | Type | Description |
---|---|---|
auto | string | The name of the Auto Scaling group. |
adjustment | string | Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage). |
cooldown? | string | A cooldown period, in seconds, that applies to a specific simple scaling policy. |
estimated | number | Not needed if the default instance warmup is defined for the group.. |
metric | string | The aggregation type for the CloudWatch metrics. |
min | number | The minimum value to scale by when the adjustment type is PercentChangeInCapacity . |
policy | string | One of the following policy types:. |
predictive | IResolvable | Predictive | A predictive scaling policy. Provides support for predefined and custom metrics. |
scaling | number | The amount by which to scale, based on the specified adjustment type. |
step | IResolvable | IResolvable | Step [] | A set of adjustments that enable you to scale based on the size of the alarm breach. |
target | IResolvable | Target | A 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
|
Predictive
(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
|
Step
[]
(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
|
Target
(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
Name | Type | Description |
---|---|---|
attr | string | Returns the ARN of a scaling policy. |
attr | string | Returns the name of a scaling policy. |
auto | string | The name of the Auto Scaling group. |
cfn | ICfn | Options for this resource, such as condition, update policy etc. |
cfn | { [string]: any } | |
cfn | string | AWS resource type. |
creation | string[] | |
logical | string | The logical ID for this CloudFormation stack element. |
node | Node | The tree node. |
ref | string | Return a string that will be resolved to a CloudFormation { Ref } for this element. |
stack | Stack | The stack in which this element is defined. |
adjustment | string | Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage). |
cooldown? | string | A cooldown period, in seconds, that applies to a specific simple scaling policy. |
estimated | number | Not needed if the default instance warmup is defined for the group.. |
metric | string | The aggregation type for the CloudWatch metrics. |
min | number | The minimum value to scale by when the adjustment type is PercentChangeInCapacity . |
policy | string | One of the following policy types:. |
predictive | IResolvable | Predictive | A predictive scaling policy. |
scaling | number | The amount by which to scale, based on the specified adjustment type. |
step | IResolvable | IResolvable | Step [] | A set of adjustments that enable you to scale based on the size of the alarm breach. |
target | IResolvable | Target | A target tracking scaling policy. |
static CFN_RESOURCE_TYPE_NAME | string | The CloudFormation resource type name for this resource class. |
attrArn
Type:
string
Returns the ARN of a scaling policy.
attrPolicyName
Type:
string
Returns the name of a scaling policy.
autoScalingGroupName
Type:
string
The name of the Auto Scaling group.
cfnOptions
Type:
ICfn
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).
cooldown?
Type:
string
(optional)
A cooldown period, in seconds, that applies to a specific simple scaling policy.
estimatedInstanceWarmup?
Type:
number
(optional)
Not needed if the default instance warmup is defined for the group..
metricAggregationType?
Type:
string
(optional)
The aggregation type for the CloudWatch metrics.
minAdjustmentMagnitude?
Type:
number
(optional)
The minimum value to scale by when the adjustment type is PercentChangeInCapacity
.
policyType?
Type:
string
(optional)
One of the following policy types:.
predictiveScalingConfiguration?
Type:
IResolvable
|
Predictive
(optional)
A predictive scaling policy.
Provides support for predefined and custom metrics.
scalingAdjustment?
Type:
number
(optional)
The amount by which to scale, based on the specified adjustment type.
stepAdjustments?
Type:
IResolvable
|
IResolvable
|
Step
[]
(optional)
A set of adjustments that enable you to scale based on the size of the alarm breach.
targetTrackingConfiguration?
Type:
IResolvable
|
Target
(optional)
A target tracking scaling policy.
Provides support for predefined or custom metrics.
static CFN_RESOURCE_TYPE_NAME
Type:
string
The CloudFormation resource type name for this resource class.
Methods
Name | Description |
---|---|
add | Syntactic sugar for addOverride(path, undefined) . |
add | Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned. |
add | Indicates that this resource depends on another resource and cannot be provisioned unless the other resource has been successfully provisioned. |
add | Add a value to the CloudFormation Resource Metadata. |
add | Adds an override to the synthesized CloudFormation resource. |
add | Adds an override that deletes the value of a property from the resource definition. |
add | Adds an override to a resource property. |
apply | Sets the deletion policy of the resource based on the removal policy specified. |
get | Returns a token for an runtime attribute of this resource. |
get | Retrieve a value value from the CloudFormation Resource Metadata. |
inspect(inspector) | Examines the CloudFormation resource and discloses attributes. |
obtain | Retrieves an array of resources this resource depends on. |
obtain | Get a shallow copy of dependencies between this resource and other resources in the same stack. |
override | Overrides the auto-generated logical ID with a specific ID. |
remove | Indicates that this resource no longer depends on another resource. |
replace | Replaces one dependency with another. |
to | Returns a string representation of this construct. |
protected render |
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
Cfn
Resource
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
Cfn
Resource
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.
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
Removal
Policy - options
Removal
Policy Options
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:
getAtt(attributeName, typeHint?)
public getAtt(attributeName: string, typeHint?: ResolutionTypeHint): Reference
Parameters
- attributeName
string
— The name of the attribute. - typeHint
Resolution
Type Hint
Returns
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.
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
Tree
— tree inspector to collect and process attributes.Inspector
Examines the CloudFormation resource and discloses attributes.
obtainDependencies()
public obtainDependencies(): Stack | CfnResource[]
Returns
Stack
|
Cfn
Resource []
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
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
Cfn
Resource
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
Cfn
— The dependency to replace.Resource - newTarget
Cfn
— The new dependency to add.Resource
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 }