Skip to content

ScalingPolicy

Source: src/AWS/AutoScaling/ScalingPolicy.ts

A target-tracking scaling policy for an Auto Scaling Group. EC2 Auto Scaling creates and manages the CloudWatch alarms that keep the tracked metric at targetValue by adjusting the group’s desired capacity.

Track average CPU utilization

import { AutoScalingGroup, ScalingPolicy } from "alchemy/AWS/AutoScaling";
const group = yield* AutoScalingGroup("Fleet", {
launchTemplate: template,
subnetIds: [subnet.subnetId],
minSize: 1,
maxSize: 4,
});
const policy = yield* ScalingPolicy("CpuPolicy", {
autoScalingGroup: group,
predefinedMetricType: "ASGAverageCPUUtilization",
targetValue: 60,
});

Scale on ALB requests per target without scale-in

const policy = yield* ScalingPolicy("RequestPolicy", {
autoScalingGroup: group,
predefinedMetricType: "ALBRequestCountPerTarget",
targetValue: 1000,
disableScaleIn: true,
estimatedInstanceWarmup: "3 minutes",
});