Skip to content
RankCore.AI
← All posts

AWS Auto Scaling Groups Explained: Scale Out, Scale In, and Self-Heal Automatically

· AWS, Auto Scaling, EC2, CloudWatch, Cloud

Your app gets a traffic spike at noon and goes quiet at midnight. How do you keep it fast without paying for servers you do not need? An Amazon EC2 Auto Scaling group is AWS's answer: a managed fleet that launches identical instances from a recipe, spreads them across Availability Zones, and adds, removes, or replaces them as load and health change. The short video above tells that story. This article follows the same flow, then fills in the settings you will actually configure.

The launch template is the recipe for every server

An Auto Scaling group does not invent a unique server each time it scales out. It launches another copy of a known configuration — in modern Amazon EC2 Auto Scaling, a launch template.

Launch template card listing a Linux AMI, t3.medium instance type, and sg-web security group for ports 80 and 443, under an empty Auto Scaling group spanning two Availability Zones

The launch template is the recipe for every server: machine image, instance type, and security settings. IDs in the video are shortened examples.

The video keeps the recipe simple: a Linux AMI (ami-0a1b2c is a shortened example, not a real AMI ID), instance type t3.medium, and security group sg-web on ports 80 and 443. A production template can also include an IAM instance profile, a key pair, block devices, and user data — a startup script that installs packages or pulls the latest build.

Launch templates are versioned. The group can pin a version, use $Latest (new instances pick up the newest version), or use $Default (the version you marked as default). That is a major advantage over launch configurations, the older, immutable alternative. AWS strongly recommends launch templates. Launch configurations cannot be edited after creation, cannot express a mixed instances policy, and no longer keep up with the platform: as of January 1, 2023, new EC2 instance types are not supported in them; accounts created on or after June 1, 2023 cannot create them in the console; and accounts created on or after October 1, 2024 cannot create them by any method. If you still have groups on launch configurations, migrate them.

Spread identical instances across Availability Zones

The group launches instances into the subnets you give it. Those subnets should sit in different Availability Zones (AZs) in the same Region, so a single-zone impairment does not take the fleet down.

Two running instances, i-01a7 in Availability Zone A and i-02a7 in Availability Zone B, launched from the same launch template

The group launches identical instances across subnets in multiple Availability Zones. Here, i-01a7 runs in AZ A and i-02a7 runs in AZ B.

Amazon EC2 Auto Scaling tries to keep capacity balanced across the AZs enabled for the group. If one zone has more instances than another, the next scale-in usually prefers the heavier zone, and the next scale-out usually prefers the lighter one. You pass the subnets with --vpc-zone-identifier (a comma-separated list of subnet IDs). Put at least one subnet in each AZ you care about, and make sure each subnet can reach NAT or VPC endpoints and, if you use one, the load balancer target group.

Three numbers govern the fleet: min, max, and desired

Every Auto Scaling group has three size properties: MinSize, MaxSize, and DesiredCapacity. The video shows them on a 0–7 slider: minimum 2, maximum 6, and desired 2.

Capacity slider with minimum 2, desired 2, and maximum 6, and one healthy instance in each of two Availability Zones

Min is the floor (never fewer than two). Max is the ceiling, which also caps cost. Desired is how many instances the group should run right now.

Minimum is the floor — the group will not scale in below it, even if CPU is idle. Maximum is the ceiling, no matter how high the metric climbs, and it is also a cost cap. Desired is the current target. Scaling policies, scheduled actions, and some API calls move it; the group then launches or terminates instances until the in-service count matches. The invariant, which the video restates later, is minimum ≤ desired ≤ maximum. If a scheduled action tries to set desired above max, include the new max in the same action or the change will not land the way you expect.

CloudWatch watches the fleet, then the group scales out and in

Capacity by itself does not react to traffic. You attach a scaling policy, and Amazon CloudWatch supplies the metric. In the video, that metric is average CPU, with a high threshold at 70% and a low threshold at 30%. When the noon spike arrives, CPU climbs through 70% and an alarm fires: scale out by one. Desired capacity moves from 2 to 3, and a new instance, i-03a7, launches from the same template in AZ A and starts taking traffic.

Scale-out scene: CloudWatch average CPU at 86% with a scale-out alarm, desired capacity moved to 3, and instance i-03a7 launching from the template in Availability Zone A

CPU rises above 70%, a CloudWatch alarm fires, desired capacity goes from 2 to 3, and a new instance launches from the template.

After the spike, CPU falls through 30%. A scale-in alarm fires, desired capacity returns from 3 to 2, and the extra instance is drained and then terminated. The fleet is back at the minimum: one instance in each AZ.

Scale-in scene: CloudWatch average CPU at 24% with a scale-in alarm, desired capacity back at 2, and instance i-03a7 draining in Availability Zone A

CPU drops below 30%, desired capacity goes back to 2, and the extra instance drains before it is terminated.

"Draining" matters if a load balancer sits in front of the group. Amazon EC2 Auto Scaling deregisters the instance from the target group first. New requests go elsewhere, and existing connections can finish until the target group's deregistration delay expires (Elastic Load Balancing's default is 300 seconds). That delay is the modern name for connection draining. Terminate too quickly, and users mid-request can see errors even though scaling in was the right cost decision.

After scale-in, desired capacity sits at 2, between the minimum of 2 and the maximum of 6, with CloudWatch CPU back in the healthy band

Desired capacity always stays between the minimum and the maximum.

Scaling policy types, and why target tracking is usually better

The video's 70% / 30% alarm pair maps most closely to simple scaling or step scaling. Both start with a CloudWatch alarm you define. Simple scaling applies one adjustment (for example +1 or -1) and then waits for a cooldown before honoring another simple-scaling action. AWS now discourages simple scaling and cooldowns as a primary strategy. Step scaling lets you define several adjustments based on how far the metric has breached the threshold (add 1 instance at 70%, add more at 85%, and so on). It uses instance warmup rather than a simple cooldown, and can keep scaling out if the alarm stays in ALARM.

Target tracking is the modern default for dynamic scaling. You pick a metric and a target, such as average CPU of 50% or Application Load Balancer request count per target. Amazon EC2 Auto Scaling creates and manages the CloudWatch alarms for you. Think of a thermostat: it adds capacity when the metric is above the target and removes it when the metric is below, scaling in more gradually so availability stays first. Do not edit those managed alarms yourself. For the video's workload, a target tracking policy on ASGAverageCPUUtilization with a target around the middle of that 30–70% band (for example, 50%) would usually replace both alarms. Keep min 2 and max 6 so the thermostat cannot go to zero or run away on cost.

Scheduled scaling is for load you can already put on a calendar. A scheduled action sets desired, and optionally min and max, at a time you specify. It can run once or on a recurring schedule, and it does not wait for a cooldown. Predictive scaling looks at up to 14 days of CloudWatch history, needs at least 24 hours of data, and forecasts hourly capacity for the next 48 hours (the forecast refreshes every 6 hours). New policies start in forecast only mode so you can inspect the forecast before switching to forecast and scale. Predictive scaling will scale out ahead of a predicted peak, but it will not scale in on its own; you still use a dynamic policy to come back down.

Two timers are easy to confuse. A cooldown applies mainly to simple scaling. Health-check replacements do not wait for it, and scheduled actions can also run immediately. Instance warmup is what target tracking and step scaling use instead. Until warmup ends, a new instance is not counted in the group's aggregated CloudWatch metrics, which prevents a just-launched server from dragging the average down and stopping further scale-out too early. Scale-in from those policies is also blocked during warmup. Set a default instance warmup on the group so every policy can inherit it. If you leave it unset, policies fall back to the group's default cooldown.

Health checks, load balancers, and self-healing

Scaling is only half of the story. The other half is replacing instances that are no longer healthy, even when desired capacity does not change.

By default, a group uses EC2 health checks: if the instance leaves the running state, it is replaced. That catches a crash or a stop, but not a process that is up while the application is down. For a web fleet, attach an Application Load Balancer through a target group, set --health-check-type ELB, and let the load balancer's checks (protocol, path, port, thresholds) decide whether the app is actually serving traffic. The group then treats an ELB-unhealthy target as an unhealthy instance and replaces it.

Newly launched instances need time to install software and pass those checks. That is the health check grace period. In the console it defaults to 300 seconds; with the AWS CLI or an SDK the default is 0, which turns it off. Set it long enough for a cold start plus the consecutive successful checks your target group requires, but not so long that a truly bad instance sits in service. During the grace period, Auto Scaling still replaces an instance immediately if it is no longer in the EC2 running state.

The video's self-healing scene is this mechanism in action: i-02a7 in AZ B fails its health check and is marked unhealthy. The group launches i-04a7 in its place, automatically, and desired capacity stays at 2.

Self-healing: instance i-02a7 is gone from Availability Zone B and replacement instance i-04a7 is launching, labeled replaced automatically, while desired capacity stays at 2

If an instance fails its health check, the group replaces it automatically. Desired capacity does not have to change.

If you need to do work before a new instance receives traffic, or before an old one disappears, use a lifecycle hook. On launch, the instance can pause in Pending:Wait. On scale-in, it can pause in Terminating:Wait after deregistration (for example, to flush logs). The default wait is one hour; you complete the hook early or let it time out, with a default result of CONTINUE or ABANDON.

When several instances could be removed, a termination policy picks the victim. Auto Scaling still balances AZs first; the policy applies inside that choice. Unhealthy instances bypass the policy and are replaced directly. The default policy prefers outdated launch configurations or old template versions, then instances closest to their next billing hour. You can also choose built-in policies such as OldestInstance, NewestInstance, OldestLaunchTemplate, or a Lambda function that returns which instance is safe to terminate.

Cost: pay for what you need, and cap what you do not

The closing image is the point of the whole design. A 24-hour traffic curve rises toward noon and falls at night. A stepped line of server capacity follows it: more traffic, more servers; less traffic, fewer servers. You only pay for what you need, and the maximum still caps the bill.

Traffic over 24 hours with a stepped server-capacity line following the noon peak, plus callouts that more traffic means more servers and less traffic means fewer servers

Servers follow traffic. The minimum keeps a baseline at night; the maximum caps the peak.

A few well-established ways to keep that shape efficient, without guessing at prices: right-size max, because it is your hard cost ceiling during a bad metric or a burst; keep min honest (two instances across two AZs is a reasonable floor for a small web app — if min equals max, you have disabled scaling in); use a mixed instances policy (launch template required) to combine instance types and, if the workload allows, On-Demand and Spot capacity; right-size the instance type in the template, because scaling out oversized instances is still wasteful; and prefer target tracking so you are not stuck at a high desired count after the spike has passed.

A short example you can adapt

Treat the AMI, subnets, security group, and target group as placeholders. The flags below match the create-auto-scaling-group reference.

aws ec2 create-launch-template \
  --launch-template-name web-asg-template \
  --version-description v1 \
  --launch-template-data '{"ImageId":"ami-0a1b2cexample","InstanceType":"t3.medium","SecurityGroupIds":["sg-0123456789abcdef0"]}'

aws autoscaling create-auto-scaling-group \
  --auto-scaling-group-name web-asg \
  --launch-template LaunchTemplateName=web-asg-template,Version='$Latest' \
  --min-size 2 --max-size 6 --desired-capacity 2 \
  --vpc-zone-identifier "subnet-aaa,subnet-bbb" \
  --health-check-type ELB \
  --health-check-grace-period 300 \
  --default-instance-warmup 120 \
  --target-group-arns arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-tg/abcdef0123456789

aws autoscaling put-scaling-policy \
  --auto-scaling-group-name web-asg \
  --policy-name cpu-target-50 \
  --policy-type TargetTrackingScaling \
  --target-tracking-configuration '{"PredefinedMetricSpecification":{"PredefinedMetricType":"ASGAverageCPUUtilization"},"TargetValue":50.0}'

The same group in Terraform uses aws_launch_template and aws_autoscaling_group, with launch_template { id, version }, vpc_zone_identifier, health_check_type = "ELB", health_check_grace_period, and target_group_arns. In CloudFormation, the matching resources are AWS::EC2::LaunchTemplate and AWS::AutoScaling::AutoScalingGroup.

Common mistakes

  • Using only EC2 health checks in front of a load balancer, so a crashed process never gets replaced.
  • Leaving the health check grace period at 0 (the CLI default), so new instances are marked unhealthy while they are still booting.
  • Scaling on a metric that does not change with fleet size, such as raw load-balancer request count, especially with target tracking.
  • Forgetting a cooldown or warmup, then oscillating: a scale-out immediately followed by a scale-in before the new instance is serving traffic.
  • Setting min equal to max, which disables dynamic scaling, or leaving max far too high with an aggressive policy.
  • Putting all subnets in a single AZ, which removes the multi-zone benefit the video starts with.
  • Staying on launch configurations, which cannot use mixed instances and are no longer available to create in newer accounts.

FAQ

Do I still need a load balancer? Auto Scaling can work without one, but a web or API fleet almost always wants an Application Load Balancer and a target group so traffic is shared and ELB health checks can drive replacements.

What is the difference between desired capacity and the number of running instances? Desired is the target. The running (and in-service) count is current reality. They diverge briefly during launches, terminations, and replacements.

Can desired go below min if CPU is idle? No. Min is a hard floor. To run fewer instances at night, lower min with a scheduled action, or set min to 0 if the application can scale to zero.

Should I use the 70% and 30% alarms from the video in production? They are a clear teaching example of step or simple scaling. For most applications, start with target tracking and a single target, then add scheduled or predictive scaling if your traffic is regular.

Will a health-check replacement wait for a cooldown? No. Unhealthy instances are replaced without waiting for the simple-scaling cooldown.

How do I update application code on a running group? Publish a new launch template version (new AMI or new user data), point the group at $Latest or that version, and run an instance refresh so existing instances are replaced in a controlled rolling fashion.

Keep the fleet close to the work

Write a launch template, place the group in more than one AZ, set min, desired, and max, then let a policy and health checks move desired capacity and replace what fails. The video's last line is the operating principle: more traffic, more servers; less traffic, fewer servers. You only pay for what you need.

If you want more short, practical lessons like this on AI, code, cloud, and security, follow @rankcore.ai.

Want to go deeper?

Our step-by-step video courses turn these ideas into results.

See courses

Comments

Sign in or create a free account to join the discussion.

No comments yet — be the first.