4th week :- Auto Scaling Group in AWS

Lav kushwahaLav kushwaha
9 min read

๐ŸŒฉ๏ธ What is Auto Scaling in AWS? (With Real-world Example)

Imagine you run an online shopping website. During regular hours, you have moderate traffic. But during sales or festivals, traffic explodes. You donโ€™t want your site to crash, and you also donโ€™t want to waste money running too many servers during low traffic. Thatโ€™s where Auto Scaling in AWS comes in.

๐Ÿš€ Auto Scaling: The Core Concept

Auto Scaling is a cloud computing feature that automatically adjusts (increases or decreases) the number of compute resources based on traffic or workload.

  • Scale Out (Add instances) when demand increases

  • Scale In (Remove instances) when demand decreases

With Auto Scaling, you donโ€™t need to manually add or remove EC2 instances. AWS monitors the application and makes real-time decisions.

What is an Auto Scaling Group (ASG)?

An Auto Scaling Group is the main building block of Auto Scaling.

Think of it like this:

  • Auto Scaling Group = Group of EC2 instances with rules about when to grow or shrink.

  • It ensures minimum, maximum, and desired number of EC2 instances are always maintained.

Key Components of ASG:

ComponentDescription
Launch Template / Launch ConfigurationBlueprint for new EC2 instances (includes AMI, instance type, key pair, etc.)
Min/Max/Desired CapacityDefine limits for how many EC2 instances should run
Scaling PoliciesDefine how ASG should respond to changes in demand
Health ChecksAWS replaces unhealthy instances automatically
Target Groups (for Load Balancer)ASG can automatically register new instances with a Load Balancer

โš™๏ธ How Auto Scaling Works โ€“ Full Step-by-Step Guide (With Console Instructions)

๐Ÿงฉ Step-by-Step Guide to AWS Auto Scaling โ€“ Starting from AMI

This guide explains every step from choosing an AMI to configuring your Auto Scaling Group, and highlights why each step is important for your infrastructure.


โœ… Step 1: Choose an AMI (Amazon Machine Image)

๐Ÿ“Where:

AWS Console โ†’ EC2 Dashboard โ†’ Launch Templates โ†’ Create New Template โ†’ Choose AMI

๐Ÿ“˜ What is AMI?

An AMI is a pre-configured OS image that includes the operating system, application server, and applications (optional).

๐ŸŽฏ Why use it?

  • This image acts as the base template for all EC2 instances that your Auto Scaling Group will launch.

  • You can use official Amazon AMIs (Amazon Linux, Ubuntu, etc.) or create your own custom AMI with pre-installed software.

๐Ÿง  Use Case:

If you're running a Node.js app, your AMI could include:

  • Ubuntu OS

  • Node.js installed

  • App pre-cloned from GitHub

โœ… Benefit:

  • Consistency: Every new EC2 instance is identical.

  • Speed: Faster boot time with pre-installed packages.


โœ… Step 2: Create a Launch Template

๐Ÿ“Where:

EC2 Dashboard โ†’ Launch Templates โ†’ Create launch template

๐Ÿ“˜ What is it?

A Launch Template defines how your EC2 instances will be configured when Auto Scaling launches them.

Key options to fill:

  • AMI ID โ€“ (from Step 1)

  • Instance type โ€“ e.g., t3.micro

  • Key pair โ€“ for SSH access

  • Security group โ€“ to allow traffic (HTTP, HTTPS, SSH)

  • User Data โ€“ script to auto-configure instance on launch

๐Ÿง  Use Case:

Want every instance to:

  • Install Apache

  • Start a web server

  • Show "Welcome to Auto Scaling"

Use this user data:

bashCopyEdit#!/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
echo "Hello from Auto Scaling!" > /var/www/html/index.html

โœ… Benefit:

  • Automation: No manual setup.

  • Reusability: Use same template for multiple environments (prod, staging).


โœ… Step 3: Create an Auto Scaling Group (ASG)

๐Ÿ“Where:

EC2 Dashboard โ†’ Auto Scaling Groups โ†’ Create Auto Scaling Group

๐Ÿ“˜ What is it?

An ASG is a group of EC2 instances managed together, capable of automatically scaling up/down based on demand or health checks.

Key settings:

  • Attach Launch Template โ€“ Select from Step 2

  • Name your group

  • Choose network (VPC & Subnets) โ€“ Distribute across multiple Availability Zones

๐Ÿง  Use Case:

Want to keep 2โ€“5 EC2 instances running based on CPU usage? ASG makes this dynamic.

โœ… Benefit:

  • High Availability: If one instance crashes, ASG replaces it.

  • Scalability: Handles sudden traffic spikes.


โœ… Step 4: Configure Desired, Min, and Max Capacity

๐Ÿ“In ASG Setup Wizard

  • Desired capacity: Number of EC2s to start with (e.g., 2)

  • Minimum capacity: Never go below this (e.g., 1)

  • Maximum capacity: Never exceed this (e.g., 5)

๐ŸŽฏ Why?

Defines the boundaries and starting point for Auto Scaling.

๐Ÿง  Use Case:

An app that needs:

  • 1 server always running (for uptime)

  • Up to 5 servers during traffic surge

โœ… Benefit:

  • Cost-efficient: You donโ€™t pay for idle servers.

  • Always available: One instance always running.


๐Ÿ“In ASG Wizard โ†’ Load balancing section

๐Ÿ“˜ What is it?

An Application Load Balancer (ALB) distributes incoming traffic evenly across your instances.

๐Ÿง  Use Case:

Users hit yourapp.com, and ALB routes them to healthy EC2s.

โœ… Benefit:

  • Balanced load during traffic surge

  • Health checks to remove bad instances

  • HTTPS termination at load balancer


โœ… Step 6: Configure Scaling Policies

๐Ÿ“ASG Wizard โ†’ Set scaling policies

๐Ÿ“˜ What is it?

Rules that tell AWS when to scale up or down.

Options:

  • Target tracking policy (e.g., keep average CPU at 50%)

  • Step scaling (scale by steps based on thresholds)

  • Scheduled scaling (scale at fixed times)

๐Ÿง  Use Case:

If your app hits 60% CPU usage, AWS adds 1 more instance.

โœ… Benefit:

  • Performance optimization: More servers when needed

  • Cost saving: Remove extra servers during low traffic


โœ… Step 7: Set Health Checks

๐Ÿ“ASG Settings โ†’ Health Checks

๐Ÿ“˜ What is it?

Automatically check if an instance is healthy.

  • Use EC2 status checks or Load Balancer health checks.

๐Ÿง  Use Case:

If an instance becomes unresponsive, ASG terminates and replaces it.

โœ… Benefit:

  • Zero-downtime recovery

  • No manual monitoring


โœ… Step 8: Add Notifications (Optional)

๐Ÿ“In ASG wizard

  • Use SNS topics to get alerts (email, SMS) on scale events.

๐Ÿง  Use Case:

Notify DevOps when a scale-up happens.


Add tags like:

  • Environment = Production

  • Team = Backend

  • App = MyApp

โœ… Benefit:

  • Billing clarity

  • Resource organization


โœ… Step 10: Review and Create

Click Create Auto Scaling Group ๐ŸŽ‰

AWS will immediately launch your desired number of EC2 instances based on your rules.


๐Ÿ Summary of Each Step with Purpose & Benefit

StepPurposeBenefit
Choose AMIDefine base OS/app for EC2Consistency, speed
Launch TemplateDefine instance configAutomation, reusable
Auto Scaling GroupManage EC2 fleetSelf-healing, scalable
Capacity SettingsDefine size limitsCost control
Load BalancerDistribute trafficFault tolerance
Scaling PoliciesWhen to scaleElasticity
Health ChecksMonitor instance statusAuto-recovery
NotificationsAlert on eventsVisibility
TagsOrganize resourcesManage billing, infra

๐Ÿ“Š All AWS Auto Scaling Policies Explained (With Use Cases & Benefits)

When configuring an Auto Scaling Group (ASG) in AWS, choosing the right Auto Scaling policy determines how and when your infrastructure responds to changing demand.

AWS supports three main types of Auto Scaling policies:


1. ๐Ÿ” Target Tracking Scaling Policy

๐Ÿ“˜ What is it?

This is the most commonly used and recommended policy. It works like a thermostat โ€” you define a target metric (like 50% CPU), and AWS maintains it by scaling up or down automatically.

๐Ÿ›  How It Works:

  • You set a target value for a metric (like average CPU usage = 50%).

  • AWS uses CloudWatch to monitor the metric.

  • If the metric goes above the target, AWS adds instances.

  • If it goes below, AWS removes instances.

๐Ÿง  Use Case:

You want your web app to stay responsive, so you maintain:

txtCopyEditAverage CPU usage of all instances โ‰ˆ 50%

โœ… Benefits:

  • Easy to configure (no math, just a target)

  • Adaptive: AWS adjusts dynamically without fixed thresholds

  • Smart cooldowns are handled automatically

๐Ÿ”ง Metrics You Can Track:

  • CPU utilization

  • Request count per target (if using Load Balancer)

  • Custom CloudWatch metrics


2. ๐Ÿ“ˆ Step Scaling Policy

๐Ÿ“˜ What is it?

This policy allows you to define stepwise actions based on how much a metric exceeds a threshold. It gives fine-grained control over scaling behavior.

๐Ÿ›  How It Works:

You define:

  • A CloudWatch alarm (e.g., CPU > 60%)

  • Steps: How many instances to add/remove based on how high/low the metric is

๐Ÿง  Example:

txtCopyEditIf CPU > 60% for 5 mins โ†’ Add 1 instance  
If CPU > 80% for 5 mins โ†’ Add 2 instances  
If CPU < 40% for 10 mins โ†’ Remove 1 instance

โœ… Benefits:

  • Precision: You control how much to scale based on the level of load

  • Great for predictable workloads

  • Works well when combined with custom metrics

โš ๏ธ Note:

You need to manually handle cooldowns (pause time after scaling).


3. ๐Ÿ•’ Scheduled Scaling Policy

๐Ÿ“˜ What is it?

Scheduled Scaling allows you to predefine scaling actions at specific times. Ideal for known traffic patterns (e.g., business hours, marketing campaigns).

๐Ÿ›  How It Works:

You set a cron-style schedule to:

  • Set desired capacity

  • Change min or max instance counts

๐Ÿง  Use Case:

An e-commerce site expects traffic spikes every Friday 6 PM:

txtCopyEditAt 5:45 PM โ†’ Set desired capacity to 5  
At 11:00 PM โ†’ Set desired capacity back to 2

โœ… Benefits:

  • Predictable scaling

  • Saves costs when traffic patterns are known

  • Great for batch jobs, nightly ETLs, or office-hour services

โš ๏ธ Note:

  • It does not respond to real-time usage

  • Can be combined with dynamic scaling for hybrid control


๐Ÿงฎ Comparison Table

Policy TypeTriggerControl LevelBest ForCooldown
Target TrackingMetric thresholdMedium (automated)General use, web appsHandled automatically
Step ScalingMetric threshold + stepsHighCustom workflows, fine-tuned scaleManual
Scheduled ScalingTime-basedManualPredictable trafficNot needed

๐Ÿง  Choosing the Right Policy

ScenarioBest Policy
You want a simple, automatic systemโœ… Target Tracking
You want precise control over scaling stepsโœ… Step Scaling
You know your peak traffic times in advanceโœ… Scheduled Scaling
You want to mix time-based and load-based scalingโœ… Use Target + Scheduled policies together

๐Ÿงฉ Can I Combine Policies?

Yes! You can use multiple scaling policies together:

  • Combine Target Tracking with Scheduled Scaling

  • Use Step Scaling for finer adjustments along with Scheduled Scaling

0
Subscribe to my newsletter

Read articles from Lav kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lav kushwaha
Lav kushwaha