Resource: awsAutoscalingplansScalingPlan
Manages an AWS Auto Scaling scaling plan. More information can be found in the AWS Auto Scaling User Guide.
\~> NOTE: The AWS Auto Scaling service uses an AWS IAM service-linked role to manage predictive scaling of Amazon EC2 Auto Scaling groups. The service attempts to automatically create this role the first time a scaling plan with predictive scaling enabled is created. An awsIamServiceLinkedRole
resource can be used to manually manage this role. See the AWS documentation for more details.
Example Usage
Basic Dynamic Scaling
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsAvailabilityZonesAvailable =
new aws.dataAwsAvailabilityZones.DataAwsAvailabilityZones(
this,
"available",
{}
);
const awsAutoscalingGroupExample = new aws.autoscalingGroup.AutoscalingGroup(
this,
"example",
{
availabilityZones: [
`\${${dataAwsAvailabilityZonesAvailable.names.fqn}[0]}`,
],
launchConfiguration: "${aws_launch_configuration.example.name}",
maxSize: 3,
minSize: 0,
namePrefix: "example",
tags: [
{
key: "application",
propagate_at_launch: true,
value: "example",
},
],
}
);
const awsAutoscalingplansScalingPlanExample =
new aws.autoscalingplansScalingPlan.AutoscalingplansScalingPlan(
this,
"example_2",
{
applicationSource: {
tagFilter: [
{
key: "application",
values: ["example"],
},
],
},
name: "example-dynamic-cost-optimization",
scalingInstruction: [
{
maxCapacity: 3,
minCapacity: 0,
resourceId: `\${format("autoScalingGroup/%s", ${awsAutoscalingGroupExample.name})}`,
scalableDimension: "autoscaling:autoScalingGroup:DesiredCapacity",
serviceNamespace: "autoscaling",
targetTrackingConfiguration: [
{
predefinedScalingMetricSpecification: {
predefinedScalingMetricType: "ASGAverageCPUUtilization",
},
targetValue: 70,
},
],
},
],
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAutoscalingplansScalingPlanExample.overrideLogicalId("example");
Basic Predictive Scaling
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsAvailabilityZonesAvailable =
new aws.dataAwsAvailabilityZones.DataAwsAvailabilityZones(
this,
"available",
{}
);
const awsAutoscalingGroupExample = new aws.autoscalingGroup.AutoscalingGroup(
this,
"example",
{
availabilityZones: [
`\${${dataAwsAvailabilityZonesAvailable.names.fqn}[0]}`,
],
launchConfiguration: "${aws_launch_configuration.example.name}",
maxSize: 3,
minSize: 0,
namePrefix: "example",
tags: [
{
key: "application",
propagate_at_launch: true,
value: "example",
},
],
}
);
const awsAutoscalingplansScalingPlanExample =
new aws.autoscalingplansScalingPlan.AutoscalingplansScalingPlan(
this,
"example_2",
{
applicationSource: {
tagFilter: [
{
key: "application",
values: ["example"],
},
],
},
name: "example-predictive-cost-optimization",
scalingInstruction: [
{
disableDynamicScaling: true,
maxCapacity: 3,
minCapacity: 0,
predefinedLoadMetricSpecification: {
predefinedLoadMetricType: "ASGTotalCPUUtilization",
},
predictiveScalingMaxCapacityBehavior:
"SetForecastCapacityToMaxCapacity",
predictiveScalingMode: "ForecastAndScale",
resourceId: `\${format("autoScalingGroup/%s", ${awsAutoscalingGroupExample.name})}`,
scalableDimension: "autoscaling:autoScalingGroup:DesiredCapacity",
serviceNamespace: "autoscaling",
targetTrackingConfiguration: [
{
predefinedScalingMetricSpecification: {
predefinedScalingMetricType: "ASGAverageCPUUtilization",
},
targetValue: 70,
},
],
},
],
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAutoscalingplansScalingPlanExample.overrideLogicalId("example");
Argument Reference
The following arguments are supported:
name
- (Required) Name of the scaling plan. Names cannot contain vertical bars, colons, or forward slashes.applicationSource
- (Required) CloudFormation stack or set of tags. You can create one scaling plan per application source.scalingInstruction
- (Required) Scaling instructions. More details can be found in the AWS Auto Scaling API Reference.
The applicationSource
object supports the following:
cloudformationStackArn
- (Optional) ARN of a AWS CloudFormation stack.tagFilter
- (Optional) Set of tags.
The tagFilter
object supports the following:
key
- (Required) Tag key.values
- (Optional) Tag values.
The scalingInstruction
object supports the following:
maxCapacity
- (Required) Maximum capacity of the resource. The exception to this upper limit is if you specify a non-default setting forpredictiveScalingMaxCapacityBehavior
.minCapacity
- (Required) Minimum capacity of the resource.resourceId
- (Required) ID of the resource. This string consists of the resource type and unique identifier.scalableDimension
- (Required) Scalable dimension associated with the resource. Valid values:autoscaling:autoScalingGroup:desiredCapacity
,dynamodb:index:readCapacityUnits
,dynamodb:index:writeCapacityUnits
,dynamodb:table:readCapacityUnits
,dynamodb:table:writeCapacityUnits
,ecs:service:desiredCount
,ec2:spotFleetRequest:targetCapacity
,rds:cluster:readReplicaCount
.serviceNamespace
- (Required) Namespace of the AWS service. Valid values:autoscaling
,dynamodb
,ecs
,ec2
,rds
.targetTrackingConfiguration
- (Required) Structure that defines new target tracking configurations. Each of these structures includes a specific scaling metric and a target value for the metric, along with various parameters to use with dynamic scaling. More details can be found in the AWS Auto Scaling API Reference.customizedLoadMetricSpecification
- (Optional) Customized load metric to use for predictive scaling. You must specify eithercustomizedLoadMetricSpecification
orpredefinedLoadMetricSpecification
when configuring predictive scaling. More details can be found in the AWS Auto Scaling API Reference.disableDynamicScaling
- (Optional) Boolean controlling whether dynamic scaling by AWS Auto Scaling is disabled. Defaults tofalse
.predefinedLoadMetricSpecification
- (Optional) Predefined load metric to use for predictive scaling. You must specify eitherpredefinedLoadMetricSpecification
orcustomizedLoadMetricSpecification
when configuring predictive scaling. More details can be found in the AWS Auto Scaling API Reference.predictiveScalingMaxCapacityBehavior
- (Optional) Defines the behavior that should be applied if the forecast capacity approaches or exceeds the maximum capacity specified for the resource. Valid values:setForecastCapacityToMaxCapacity
,setMaxCapacityAboveForecastCapacity
,setMaxCapacityToForecastCapacity
.predictiveScalingMaxCapacityBuffer
- (Optional) Size of the capacity buffer to use when the forecast capacity is close to or exceeds the maximum capacity.predictiveScalingMode
- (Optional) Predictive scaling mode. Valid values:forecastAndScale
,forecastOnly
.scalingPolicyUpdateBehavior
- (Optional) Controls whether a resource's externally created scaling policies are kept or replaced. Valid values:keepExternalPolicies
,replaceExternalPolicies
. Defaults tokeepExternalPolicies
.scheduledActionBufferTime
- (Optional) Amount of time, in seconds, to buffer the run time of scheduled scaling actions when scaling out.
The customizedLoadMetricSpecification
object supports the following:
metricName
- (Required) Name of the metric.namespace
- (Required) Namespace of the metric.statistic
- (Required) Statistic of the metric. Currently, the value must always besum
.dimensions
- (Optional) Dimensions of the metric.unit
- (Optional) Unit of the metric.
The predefinedLoadMetricSpecification
object supports the following:
predefinedLoadMetricType
- (Required) Metric type. Valid values:albTargetGroupRequestCount
,asgTotalCpuUtilization
,asgTotalNetworkIn
,asgTotalNetworkOut
.resourceLabel
- (Optional) Identifies the resource associated with the metric type.
The targetTrackingConfiguration
object supports the following:
targetValue
- (Required) Target value for the metric.customizedScalingMetricSpecification
- (Optional) Customized metric. You can specify eithercustomizedScalingMetricSpecification
orpredefinedScalingMetricSpecification
. More details can be found in the AWS Auto Scaling API Reference.disableScaleIn
- (Optional) Boolean indicating whether scale in by the target tracking scaling policy is disabled. Defaults tofalse
.predefinedScalingMetricSpecification
- (Optional) Predefined metric. You can specify eitherpredefinedScalingMetricSpecification
orcustomizedScalingMetricSpecification
. More details can be found in the AWS Auto Scaling API Reference.estimatedInstanceWarmup
- (Optional) Estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics. This value is used only if the resource is an Auto Scaling group.scaleInCooldown
- (Optional) Amount of time, in seconds, after a scale in activity completes before another scale in activity can start. This value is not used if the scalable resource is an Auto Scaling group.scaleOutCooldown
- (Optional) Amount of time, in seconds, after a scale-out activity completes before another scale-out activity can start. This value is not used if the scalable resource is an Auto Scaling group.
The customizedScalingMetricSpecification
object supports the following:
metricName
- (Required) Name of the metric.namespace
- (Required) Namespace of the metric.statistic
- (Required) Statistic of the metric. Valid values:average
,maximum
,minimum
,sampleCount
,sum
.dimensions
- (Optional) Dimensions of the metric.unit
- (Optional) Unit of the metric.
The predefinedScalingMetricSpecification
object supports the following:
predefinedScalingMetricType
- (Required) Metric type. Valid values:albRequestCountPerTarget
,asgAverageCpuUtilization
,asgAverageNetworkIn
,asgAverageNetworkOut
,dynamoDbReadCapacityUtilization
,dynamoDbWriteCapacityUtilization
,ecsServiceAverageCpuUtilization
,ecsServiceAverageMemoryUtilization
,ec2SpotFleetRequestAverageCpuUtilization
,ec2SpotFleetRequestAverageNetworkIn
,ec2SpotFleetRequestAverageNetworkOut
,rdsReaderAverageCpuUtilization
,rdsReaderAverageDatabaseConnections
.resourceLabel
- (Optional) Identifies the resource associated with the metric type.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
id
- Scaling plan identifier.scalingPlanVersion
- The version number of the scaling plan. This value is always 1.
Import
Auto Scaling scaling plans can be imported using the name
, e.g.,