Resource: awsAppautoscalingPolicy
Provides an Application AutoScaling Policy resource.
Example Usage
DynamoDB Table Autoscaling
/*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 awsAppautoscalingTargetDynamodbTableReadTarget =
new aws.appautoscalingTarget.AppautoscalingTarget(
this,
"dynamodb_table_read_target",
{
maxCapacity: 100,
minCapacity: 5,
resourceId: "table/tableName",
scalableDimension: "dynamodb:table:ReadCapacityUnits",
serviceNamespace: "dynamodb",
}
);
new aws.appautoscalingPolicy.AppautoscalingPolicy(
this,
"dynamodb_table_read_policy",
{
name: `DynamoDBReadCapacityUtilization:\${${awsAppautoscalingTargetDynamodbTableReadTarget.resourceId}}`,
policyType: "TargetTrackingScaling",
resourceId: awsAppautoscalingTargetDynamodbTableReadTarget.resourceId,
scalableDimension:
awsAppautoscalingTargetDynamodbTableReadTarget.scalableDimension,
serviceNamespace:
awsAppautoscalingTargetDynamodbTableReadTarget.serviceNamespace,
targetTrackingScalingPolicyConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: "DynamoDBReadCapacityUtilization",
},
targetValue: 70,
},
}
);
ECS Service Autoscaling
/*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 awsAppautoscalingTargetEcsTarget =
new aws.appautoscalingTarget.AppautoscalingTarget(this, "ecs_target", {
maxCapacity: 4,
minCapacity: 1,
resourceId: "service/clusterName/serviceName",
scalableDimension: "ecs:service:DesiredCount",
serviceNamespace: "ecs",
});
new aws.appautoscalingPolicy.AppautoscalingPolicy(this, "ecs_policy", {
name: "scale-down",
policyType: "StepScaling",
resourceId: awsAppautoscalingTargetEcsTarget.resourceId,
scalableDimension: awsAppautoscalingTargetEcsTarget.scalableDimension,
serviceNamespace: awsAppautoscalingTargetEcsTarget.serviceNamespace,
stepScalingPolicyConfiguration: {
adjustmentType: "ChangeInCapacity",
cooldown: 60,
metricAggregationType: "Maximum",
stepAdjustment: [
{
metricIntervalUpperBound: 0,
scalingAdjustment: -1,
},
],
},
});
Preserve desired count when updating an autoscaled ECS Service
/*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 awsEcsServiceEcsService = new aws.ecsService.EcsService(
this,
"ecs_service",
{
cluster: "clusterName",
desiredCount: 2,
name: "serviceName",
taskDefinition: "taskDefinitionFamily:1",
}
);
awsEcsServiceEcsService.addOverride("lifecycle", [
{
ignore_changes: ["${desired_count}"],
},
]);
Aurora Read Replica Autoscaling
/*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 awsAppautoscalingTargetReplicas =
new aws.appautoscalingTarget.AppautoscalingTarget(this, "replicas", {
maxCapacity: 15,
minCapacity: 1,
resourceId: "cluster:${aws_rds_cluster.example.id}",
scalableDimension: "rds:cluster:ReadReplicaCount",
serviceNamespace: "rds",
});
const awsAppautoscalingPolicyReplicas =
new aws.appautoscalingPolicy.AppautoscalingPolicy(this, "replicas_1", {
name: "cpu-auto-scaling",
policyType: "TargetTrackingScaling",
resourceId: awsAppautoscalingTargetReplicas.resourceId,
scalableDimension: awsAppautoscalingTargetReplicas.scalableDimension,
serviceNamespace: awsAppautoscalingTargetReplicas.serviceNamespace,
targetTrackingScalingPolicyConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: "RDSReaderAverageCPUUtilization",
},
scaleInCooldown: 300,
scaleOutCooldown: 300,
targetValue: 75,
},
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAppautoscalingPolicyReplicas.overrideLogicalId("replicas");
Argument Reference
The following arguments are supported:
name
- (Required) Name of the policy. Must be between 1 and 255 characters in length.policyType
- (Optional) Policy type. Valid values arestepScaling
andtargetTrackingScaling
. Defaults tostepScaling
. Certain services only support only one policy type. For more information see the Target Tracking Scaling Policies and Step Scaling Policies documentation.resourceId
- (Required) Resource type and unique identifier string for the resource associated with the scaling policy. Documentation can be found in theresourceId
parameter at: AWS Application Auto Scaling API ReferencescalableDimension
- (Required) Scalable dimension of the scalable target. Documentation can be found in thescalableDimension
parameter at: AWS Application Auto Scaling API ReferenceserviceNamespace
- (Required) AWS service namespace of the scalable target. Documentation can be found in theserviceNamespace
parameter at: AWS Application Auto Scaling API ReferencestepScalingPolicyConfiguration
- (Optional) Step scaling policy configuration, requirespolicyType = "stepScaling"
(default). See supported fields below.targetTrackingScalingPolicyConfiguration
- (Optional) Target tracking policy, requirespolicyType = "targetTrackingScaling"
. See supported fields below.
stepScalingPolicyConfiguration
The stepScalingPolicyConfiguration
configuration block supports the following arguments:
adjustmentType
- (Required) Whether the adjustment is an absolute number or a percentage of the current capacity. Valid values arechangeInCapacity
,exactCapacity
, andpercentChangeInCapacity
.cooldown
- (Required) Amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start.metricAggregationType
- (Optional) Aggregation type for the policy's metrics. Valid values are "Minimum", "Maximum", and "Average". Without a value, AWS will treat the aggregation type as "Average".minAdjustmentMagnitude
- (Optional) Minimum number to adjust your scalable dimension as a result of a scaling activity. If the adjustment type is PercentChangeInCapacity, the scaling policy changes the scalable dimension of the scalable target by this amount.stepAdjustment
- (Optional) Set of adjustments that manage scaling. These have the following structure:
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.appautoscalingPolicy.AppautoscalingPolicy(this, "ecs_policy", {
stepScalingPolicyConfiguration: {
stepAdjustment: [
{
metricIntervalLowerBound: 1,
metricIntervalUpperBound: 2,
scalingAdjustment: -1,
},
{
metricIntervalLowerBound: 2,
metricIntervalUpperBound: 3,
scalingAdjustment: 1,
},
],
},
});
metricIntervalLowerBound
- (Optional) Lower bound for the difference between the alarm threshold and the CloudWatch metric. Without a value, AWS will treat this bound as negative infinity.metricIntervalUpperBound
- (Optional) Upper bound for the difference between the alarm threshold and the CloudWatch metric. Without a value, AWS will treat this bound as infinity. The upper bound must be greater than the lower bound.scalingAdjustment
- (Required) Number of members by which to scale, when the adjustment bounds are breached. A positive value scales up. A negative value scales down.
targetTrackingScalingPolicyConfiguration
The targetTrackingScalingPolicyConfiguration
configuration block supports the following arguments:
targetValue
- (Required) Target value for the metric.disableScaleIn
- (Optional) Whether scale in by the target tracking policy is disabled. If the value is true, scale in is disabled and the target tracking policy won't remove capacity from the scalable resource. Otherwise, scale in is enabled and the target tracking policy can remove capacity from the scalable resource. The default value isfalse
.scaleInCooldown
- (Optional) Amount of time, in seconds, after a scale in activity completes before another scale in activity can start.scaleOutCooldown
- (Optional) Amount of time, in seconds, after a scale out activity completes before another scale out activity can start.customizedMetricSpecification
- (Optional) Custom CloudWatch metric. Documentation can be found at: AWS Customized Metric Specification. See supported fields below.predefinedMetricSpecification
- (Optional) Predefined metric. See supported fields below.
target_tracking_scaling_policy_configuration customized_metric_specification
Example usage:
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.appautoscalingPolicy.AppautoscalingPolicy(this, "example", {
policyType: "TargetTrackingScaling",
targetTrackingScalingPolicyConfiguration: {
customizedMetricSpecification: {
dimensions: [
{
name: "MyOptionalMetricDimensionName",
value: "MyOptionalMetricDimensionValue",
},
],
metricName: "MyUtilizationMetric",
namespace: "MyNamespace",
statistic: "Average",
unit: "Percent",
},
targetValue: 40,
},
});
The targetTrackingScalingPolicyConfiguration
customizedMetricSpecification
configuration block supports the following arguments:
dimensions
- (Optional) Configuration block(s) with the dimensions of the metric if the metric was published with dimensions. Detailed below.metricName
- (Required) Name of the metric.namespace
- (Required) Namespace of the metric.statistic
- (Required) Statistic of the metric. Valid values:average
,minimum
,maximum
,sampleCount
, andsum
.unit
- (Optional) Unit of the metric.
target_tracking_scaling_policy_configuration customized_metric_specification dimensions
The targetTrackingScalingPolicyConfiguration
customizedMetricSpecification
dimensions
configuration block supports the following arguments:
name
- (Required) Name of the dimension.value
- (Required) Value of the dimension.
target_tracking_scaling_policy_configuration predefined_metric_specification
The targetTrackingScalingPolicyConfiguration
predefinedMetricSpecification
configuration block supports the following arguments:
predefinedMetricType
- (Required) Metric type.resourceLabel
- (Optional) Reserved for future use if thepredefinedMetricType
is notalbRequestCountPerTarget
. If thepredefinedMetricType
isalbRequestCountPerTarget
, you must specify this argument. Documentation can be found at: AWS Predefined Scaling Metric Specification. Must be less than or equal to 1023 characters in length.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
alarmArns
- List of CloudWatch alarm ARNs associated with the scaling policy.arn
- ARN assigned by AWS to the scaling policy.name
- Scaling policy's name.policyType
- Scaling policy's type.
Import
Application AutoScaling Policy can be imported using the serviceNamespace
, resourceId
, scalableDimension
and policyName
separated by /
.