ScalingPolicy
Source:
src/AWS/ApplicationAutoScaling/ScalingPolicy.ts
An Application Auto Scaling scaling policy attached to a scalable target.
Supports TargetTrackingScaling (Application Auto Scaling creates and
manages the CloudWatch alarms) and StepScaling (you attach the policy to
your own alarm). The policy applies to the scalable target identified by
the (serviceNamespace, resourceId, scalableDimension) triple, which
must be registered (see ScalableTarget) before the policy is
created — pass the target’s outputs so deployment orders correctly.
Target Tracking
Section titled “Target Tracking”Track ECS Service CPU
const target = yield* ScalableTarget("ApiScaling", { serviceNamespace: "ecs", resourceId: Output.interpolate`service/${cluster.clusterName}/${service.serviceName}`, scalableDimension: "ecs:service:DesiredCount", minCapacity: 1, maxCapacity: 3,});
yield* ScalingPolicy("ApiCpuPolicy", { serviceNamespace: target.serviceNamespace, resourceId: target.resourceId, scalableDimension: target.scalableDimension, targetTracking: { TargetValue: 60, PredefinedMetricSpecification: { PredefinedMetricType: "ECSServiceAverageCPUUtilization", }, ScaleOutCooldown: 60, ScaleInCooldown: 60, },});Track a Customized Metric
yield* ScalingPolicy("QueueDepthPolicy", { serviceNamespace: target.serviceNamespace, resourceId: target.resourceId, scalableDimension: target.scalableDimension, targetTracking: { TargetValue: 100, CustomizedMetricSpecification: { MetricName: "ApproximateNumberOfMessagesVisible", Namespace: "AWS/SQS", Dimensions: [{ Name: "QueueName", Value: "my-queue" }], Statistic: "Average", }, },});Step Scaling
Section titled “Step Scaling”yield* ScalingPolicy("ApiStepPolicy", { serviceNamespace: target.serviceNamespace, resourceId: target.resourceId, scalableDimension: target.scalableDimension, stepScaling: { AdjustmentType: "ChangeInCapacity", Cooldown: 60, MetricAggregationType: "Average", StepAdjustments: [ { MetricIntervalLowerBound: 0, ScalingAdjustment: 1 }, ], },});