EC2 Auto Scaling and Load Balancers: A Practical Setup Guide

EC2 Auto Scaling and Load Balancers: A Practical Setup Guide

Written by

in

A single EC2 instance is a single point of failure. Put two or more behind a load balancer and let an Auto Scaling group manage them, and the application keeps running when an instance fails, an Availability Zone has a problem, or traffic doubles at lunchtime.

This guide explains how the two services fit together, which load balancer to pick, how scaling policies and health checks work, and how to roll out new versions without downtime.

How the pieces fit

Elastic Load Balancing gives users one stable endpoint and spreads requests across healthy targets in several AZs. EC2 Auto Scaling keeps a group of instances at the size you want, launches replacements for unhealthy ones and changes capacity based on demand. When the group is attached to a load balancer target group, new instances register automatically and terminated ones are drained first.

AWS documents both in the EC2 Auto Scaling user guide and the Elastic Load Balancing user guide.

EC2 Auto Scaling with a load balancer: the load balancer spreads traffic, the Auto Scaling group replaces and adds instances, and scaling policies follow demand
The load balancer spreads traffic, the Auto Scaling group keeps the right number of healthy instances behind it.

Choosing a load balancer

TypeLayerBest for
Application Load BalancerHTTP and HTTPSWebsites, APIs, path and host routing, redirects, WebSockets
Network Load BalancerTCP, UDP, TLSVery high throughput, low latency, static IPs, non-HTTP protocols
Gateway Load BalancerIP packetsInserting firewalls and inspection appliances
Classic Load BalancerLegacyOlder setups only; migrate to ALB or NLB

For most web applications, choose an ALB. It terminates HTTPS with a free certificate from AWS Certificate Manager and can route several domains to different target groups, which also saves public IPv4 addresses compared with a public IP per server. The public IPv4 costs guide explains why that matters.

Auto Scaling group basics

  • Launch template: the AMI, instance type, security groups, IAM role and user data for new instances.
  • Minimum, desired and maximum capacity: the floor, the current target and the ceiling.
  • Subnets: private subnets in two or more AZs; the group balances instances across them.
  • Mixed instances policy: optional, lets the group use several instance types and Spot capacity.

Keep instances replaceable. Anything that must survive, such as uploads or sessions, belongs in S3, EFS, a database or a cache, not on the instance disk.

Scaling policies

  • Target tracking: keep a metric at a target, for example average CPU at 50% or requests per target at a set number. This is the best default.
  • Step scaling: add or remove different amounts depending on how far a CloudWatch alarm is breached.
  • Scheduled scaling: change capacity at known times, such as business hours or a sale.
  • Predictive scaling: forecasts daily and weekly patterns and scales ahead of them.

Set a sensible instance warmup so new instances are not counted before they are ready, and make the maximum high enough to absorb peaks but low enough to protect the budget.

Health checks

By default an Auto Scaling group uses EC2 status checks, which only confirm the virtual machine is running. Turn on ELB health checks for the group so it also replaces instances whose application stops responding. Point the target group health check at a lightweight path such as /health that checks the application but does not call slow dependencies, and give new instances a grace period long enough to boot.

Step-by-step setup

  1. Create a launch template with your AMI, instance type, security group and IAM role. Use Session Manager instead of SSH keys; the secure EC2 access guide explains how.
  2. Create a target group for the application port and set its health check path.
  3. Create an internet-facing ALB in public subnets in at least two AZs, with an HTTPS listener and an HTTP-to-HTTPS redirect.
  4. Create the Auto Scaling group in private subnets in the same AZs, attach it to the target group, and turn on ELB health checks.
  5. Set minimum 2, desired 2 and a reasonable maximum, then add a target tracking policy.
  6. Test by terminating an instance and confirming the group replaces it without errors at the load balancer.

The public vs private subnets guide covers the network layout behind these steps.

Deploying updates

Build a new AMI or update user data, create a new launch template version, and start an instance refresh. The group replaces instances in batches while keeping a minimum healthy percentage, and can roll back automatically if new instances fail health checks. For bigger changes, a blue/green approach with a second target group lets you switch traffic at the listener.

Costs and quotas

Auto Scaling is free; you pay for the instances, the load balancer’s hourly and capacity-unit charges, and any public IPv4 addresses. Adding Spot to the group can cut instance cost sharply, as the Spot Instances guide explains.

Scaling only works if the account is allowed to launch the instances. vCPU quotas are per Region and new accounts often start low, so a policy that wants ten instances can fail silently at four. Check quotas before launch, and if you need capacity quickly, compare the limits listed with each AWS account before you buy.

Common mistakes

  • Running the group in a single AZ.
  • Leaving health checks on EC2 only, so broken applications are never replaced.
  • Storing uploads or sessions on the instance disk.
  • A health check path that depends on the database, so one slow query takes every instance out.
  • A maximum capacity higher than the account’s vCPU quota allows.

Auto Scaling and load balancer questions

Does EC2 Auto Scaling cost extra?

No. There is no charge for Auto Scaling itself. You pay for the EC2 instances, EBS volumes, load balancers and CloudWatch features it uses.

Which load balancer should I use for a website?

An Application Load Balancer is the usual choice for websites and HTTP APIs. It supports HTTPS termination, host and path-based routing, and redirects. Use a Network Load Balancer for TCP or UDP traffic or when you need static IP addresses.

What is the difference between EC2 and ELB health checks?

EC2 health checks only confirm the instance is running and passing system checks. ELB health checks call your application, so turning them on in the Auto Scaling group replaces instances whose application has stopped responding.

Should I use launch templates or launch configurations?

Use launch templates. AWS no longer adds new instance types or features to launch configurations, and launch templates support mixed instances, Spot and versioning.

How do I update instances in an Auto Scaling group?

Create a new launch template version with the updated AMI or settings, then start an instance refresh. The group replaces instances in batches while keeping a minimum percentage healthy.

Editorial guide by Mark Biden · Reviewed 24 November 2026. Official sources are linked beside the relevant sections; AWS features, quotas and prices change, so confirm details in the AWS console before relying on them.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *