Back to: AWS-Basics-Advanced
AWS Launch Templates and Auto Scaling Groups (Complete Guide)
Managing EC2 instances manually is fine for small setups — but what happens when your application needs to handle traffic spikes automatically or recover from failures without human intervention?
That’s where Launch Templates and Auto Scaling Groups (ASG) come in!
They help you automate EC2 instance creation, scaling, and management, ensuring performance, availability, and cost efficiency — all hands-free.
☁️ 1. What is a Launch Template?
A Launch Template is a blueprint that defines how your EC2 instances should be launched.
It stores all configuration details like:
-
AMI ID (Amazon Machine Image)
-
Instance type (e.g., t3.micro)
-
Key pair
-
Security groups
-
Network configuration
-
User data scripts (for automation)
-
EBS volume configuration
Once created, this template can be reused by Auto Scaling Groups, EC2 Fleet, or even manual launches.
🧩 Key Benefits of Launch Templates
✅ Simplifies instance launches
✅ Maintains version control (v1, v2, etc.)
✅ Supports spot and on-demand instance mix
✅ Saves time when deploying identical servers
✅ Integrates directly with Auto Scaling Groups
⚙️ How to Create a Launch Template (Step-by-Step)
1️⃣ Go to EC2 Console → Launch Templates → Create launch template
2️⃣ Enter template name and optional description
3️⃣ Choose:
-
Amazon Machine Image (AMI) → e.g., Amazon Linux 2023
-
Instance type → e.g., t3.micro
-
Key pair → for SSH access
-
Security group → allow HTTP/HTTPS/SSH
4️⃣ (Optional) Add User Data script (for setup automation):
5️⃣ Click Create launch template
Your template is now ready for use in an Auto Scaling Group!
⚙️ 2. What is an Auto Scaling Group (ASG)?
An Auto Scaling Group ensures that you always have the right number of EC2 instances running to handle current demand.
It can automatically launch, terminate, or replace EC2 instances based on conditions like:
-
CPU utilization
-
Memory usage
-
Network traffic
-
Scheduled scaling
-
Manual triggers
🧠 Simple Explanation
Think of ASG as a smart manager that:
-
Adds more workers (EC2 instances) when your website is busy.
-
Removes idle workers when traffic drops.
-
Replaces any worker who crashes — automatically!
🧩 Core Components of ASG
Component | Description |
---|---|
Launch Template | Defines how to create instances |
Scaling Policies | Rules for adding/removing instances |
Minimum Capacity | Minimum number of instances always running |
Desired Capacity | Target number of instances |
Maximum Capacity | Upper limit to prevent overspending |
Health Checks | Replace unhealthy instances automatically |
🏗️ 3. Steps to Create an Auto Scaling Group
Step 1: Go to EC2 → Auto Scaling Groups → Create Auto Scaling Group
Step 2: Choose Launch Template
Select the launch template you created earlier.
Step 3: Select VPC and Subnets
Choose multiple subnets (preferably across Availability Zones) for high availability.
Step 4: Configure Group Size
-
Minimum capacity: 1
-
Desired capacity: 1
-
Maximum capacity: 3
Types of Auto Scaling Policies
AWS provides several scaling strategies depending on your workload pattern and business goals:
1️⃣ Simple Scaling Policy
-
Uses a CloudWatch alarm to trigger scaling actions.
-
Example: If average CPU > 70% for 5 minutes → add one instance.
-
Easy to configure but reacts slowly since it waits for alarms to clear before another action.
2️⃣ Step Scaling Policy
-
Responds with different scaling actions depending on the level of metric breach.
-
Example:
-
CPU > 70% → add 1 instance
-
CPU > 90% → add 2 instances
-
-
Provides granular control and faster reaction.
3️⃣ Target Tracking Scaling Policy (Most Common)
-
Automatically maintains a target metric value.
-
Example: Keep average CPU utilization at 50%.
-
Works like a thermostat — scales up or down automatically to maintain balance.
-
Does not require manual CloudWatch alarm creation (it’s handled internally).
4️⃣ Scheduled Scaling
-
Scales your ASG based on a time schedule.
-
Example: Scale up every weekday at 9 AM and scale down at 6 PM.
-
Useful for predictable workloads (like office hours or seasonal traffic).
5️⃣ Predictive Scaling (Advanced)
-
Uses machine learning to forecast future demand and scale resources in advance.
-
Helps minimize latency and over-provisioning.
🧠 Which Scaling Policies Require CloudWatch Alarms?
Scaling Type | Requires CloudWatch Alarm? | Description |
---|---|---|
Simple Scaling | ✅ Yes | Manual alarm triggers actions. |
Step Scaling | ✅ Yes | Different alarm thresholds for different steps. |
Target Tracking | ❌ No (AWS creates internally) | Automatically maintains target metric. |
Scheduled Scaling | ❌ No | Time-based scheduling. |
Predictive Scaling | ❌ No | AI-driven prediction model. |
So — CloudWatch alarms are mandatory only for Simple and Step scaling policies.
Auto Scaling Policies: Step-by-Step Setup for EC2
We will cover three main scaling types:
-
Simple Scaling
-
Step Scaling
-
Dynamic (Target Tracking) Scaling
Pre-requisite:
You have a Launch Template or Launch Configuration ready.
You have an Auto Scaling Group (ASG) created with min/desired/max instances.
1️⃣ Simple Scaling Policy
Concept:
Simple scaling adds or removes instances when a CloudWatch alarm threshold is breached. Only one action occurs per alarm.
Step 1: Create CloudWatch Alarm
-
Go to CloudWatch → Alarms → Create Alarm
-
Select EC2 Metrics → Per-Instance Metrics → CPUUtilization
-
Configure:
-
Statistic: Average
-
Period: 5 minutes
-
Condition: > 70%
-
-
Click Next → Create Alarm
Step 2: Attach Alarm to ASG (Simple Scaling)
-
Go to EC2 → Auto Scaling Groups → Your ASG → Automatic Scaling → Add Policy
-
Select Simple Scaling
-
Name the policy:
SimpleScaleOut
-
Choose action:
-
Add 1 instance when alarm is triggered
-
-
Attach the CloudWatch alarm created earlier
-
Save policy
✅ Now, when CPU > 70%, ASG will add 1 instance automatically.
2️⃣ Step Scaling Policy
Concept:
Step scaling allows multiple thresholds with different scaling adjustments, making it more granular.
Step 1: Create CloudWatch Alarms
-
Alarm 1: CPU > 70% → add 1 instance
-
Alarm 2: CPU > 90% → add 2 instances
-
Alarm 3: CPU < 30% → remove 1 instance
Tip: Alarms can share the same metric; the ASG policy will differentiate actions based on thresholds.
Step 2: Attach Step Scaling Policy to ASG
-
Go to EC2 → Auto Scaling Groups → Your ASG → Automatic Scaling → Add Policy
-
Choose Step Scaling
-
Define step adjustments:
Metric Range Adjustment > 70% +1 instance > 90% +2 instances < 30% -1 instance -
Select the CloudWatch alarm for triggering (e.g., CPUUtilization)
-
Save policy
✅ Step scaling is more responsive than simple scaling, especially during spikes.
3️⃣ Dynamic Scaling (Target Tracking)
Concept:
Dynamic scaling maintains a target metric automatically — e.g., keep average CPU = 50%.
No need to create separate CloudWatch alarms; AWS handles it internally.
Step 1: Create Target Tracking Policy
-
Go to EC2 → Auto Scaling Groups → Your ASG → Automatic Scaling → Add Policy
-
Choose Target Tracking
-
Configure:
-
Metric type: Average CPU Utilization
-
Target value: 50%
-
Cooldown: Optional (default 300s)
-
-
Save policy
✅ AWS will now automatically scale in/out instances to maintain ~50% CPU utilization.
in most cases, you need separate CloudWatch alarms for scale-out and scale-in when using Simple or Step Scaling policies.