4th week :- Auto Scaling Group in AWS

Table of contents
- ๐ฉ๏ธ What is Auto Scaling in AWS? (With Real-world Example)
- What is an Auto Scaling Group (ASG)?
- โ๏ธ How Auto Scaling Works โ Full Step-by-Step Guide (With Console Instructions)
- ๐งฉ Step-by-Step Guide to AWS Auto Scaling โ Starting from AMI
- โ Step 1: Choose an AMI (Amazon Machine Image)
- โ Step 2: Create a Launch Template
- โ Step 3: Create an Auto Scaling Group (ASG)
- โ Step 4: Configure Desired, Min, and Max Capacity
- โ Step 5: Attach a Load Balancer (Optional but Recommended)
- โ Step 6: Configure Scaling Policies
- โ Step 7: Set Health Checks
- โ Step 8: Add Notifications (Optional)
- โ Step 9: Tags (Recommended)
- โ Step 10: Review and Create
- ๐ Summary of Each Step with Purpose & Benefit
- ๐ All AWS Auto Scaling Policies Explained (With Use Cases & Benefits)
๐ฉ๏ธ 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:
Component | Description |
Launch Template / Launch Configuration | Blueprint for new EC2 instances (includes AMI, instance type, key pair, etc.) |
Min/Max/Desired Capacity | Define limits for how many EC2 instances should run |
Scaling Policies | Define how ASG should respond to changes in demand |
Health Checks | AWS 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.
โ Step 5: Attach a Load Balancer (Optional but Recommended)
๐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.
โ Step 9: Tags (Recommended)
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
Step | Purpose | Benefit |
Choose AMI | Define base OS/app for EC2 | Consistency, speed |
Launch Template | Define instance config | Automation, reusable |
Auto Scaling Group | Manage EC2 fleet | Self-healing, scalable |
Capacity Settings | Define size limits | Cost control |
Load Balancer | Distribute traffic | Fault tolerance |
Scaling Policies | When to scale | Elasticity |
Health Checks | Monitor instance status | Auto-recovery |
Notifications | Alert on events | Visibility |
Tags | Organize resources | Manage 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 Type | Trigger | Control Level | Best For | Cooldown |
Target Tracking | Metric threshold | Medium (automated) | General use, web apps | Handled automatically |
Step Scaling | Metric threshold + steps | High | Custom workflows, fine-tuned scale | Manual |
Scheduled Scaling | Time-based | Manual | Predictable traffic | Not needed |
๐ง Choosing the Right Policy
Scenario | Best 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
Subscribe to my newsletter
Read articles from Lav kushwaha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
