Skip to main content

Command Palette

Search for a command to run...

Implementing EC2 Auto Scaling Using CloudWatch Metrics (Hands-On Lab)

Published
3 min read
Implementing EC2 Auto Scaling Using CloudWatch Metrics (Hands-On Lab)

📌 Objective

In this hands-on lab, I practiced Amazon EC2 Auto Scaling by configuring a scaling policy based on CloudWatch CPU utilization metrics.
The goal was to automatically scale out EC2 instances when average CPU utilization crosses 50%, and verify the behavior by generating load on the instance.


🧱 Prerequisites

Before starting, the following were required:

  • An active AWS account

  • Basic understanding of:

    • EC2

    • CloudWatch

    • Auto Scaling concepts

  • Access to the EC2 dashboard

  • SSH access to EC2 instances


🧱 Services Used (Brief Overview)

🔹 Amazon EC2

Used to launch compute instances and define launch configurations for the Auto Scaling Group.

🔹 Amazon CloudWatch

Monitored CPU utilization metrics and triggered scaling actions based on defined thresholds.

🔹 Amazon EC2 Auto Scaling

Automatically added or removed EC2 instances based on CloudWatch metrics.


🧠 Auto Scaling Basics

Before implementation, I reviewed the core concepts:

🔸 Vertical Scaling

  • Increasing the capacity (CPU/RAM) of a single instance

🔸 Horizontal Scaling

  • Adding or removing multiple instances

🔸 Auto Scaling

  • Part of horizontal scaling

  • Scales EC2 instances automatically based on CloudWatch metrics

  • Supports:

    • Scale-out (add instances)

    • Scale-in (remove instances)


🧪 Step-by-Step Lab Execution


Step 1️⃣ Create Launch Configuration

  1. Navigate to EC2 Dashboard

  2. Go to Launch Configurations

  3. Click Create launch configuration

  4. Select:

    • Amazon Machine Image (AMI)

    • Instance type

  5. Enable Detailed Monitoring (important for faster scaling response)

  6. Configure remaining settings

  7. Create the launch configuration


Step 2️⃣ Create Auto Scaling Group

  1. Navigate to Auto Scaling Groups

  2. Click Create Auto Scaling Group

  3. Select the previously created Launch Configuration

  4. Choose:

    • VPC

    • Subnet

  5. Set desired, minimum, and maximum instance capacity


Step 3️⃣ Configure Scaling Policy

  1. Choose Target Tracking Scaling Policy

  2. Select metric:

    • Average CPU Utilization
  3. Set target value:

    • 50%
  4. (Optional) Configure notifications

  5. Create the Auto Scaling Group


Step 4️⃣ Verify Auto Scaling Group Creation

  • Confirm Auto Scaling Group status

  • Ensure initial EC2 instance is running

  • Verify instance is launched via the Auto Scaling Group


Step 5️⃣ Generate CPU Load for Testing

To test scaling behavior, I increased CPU utilization beyond 50%.

  1. Connect to the EC2 instance using SSH

  2. Install the stress utility

  3. Run the stress command to increase CPU usage


Step 6️⃣ Monitor CPU Utilization in CloudWatch

  1. Navigate to CloudWatch → Metrics

  2. Open EC2 → Per-Instance Metrics

  3. Observe CPU utilization crossing 50%


Step 7️⃣ Observe Auto Scaling Action

Once CPU utilization exceeded the threshold:

  • Auto Scaling policy was triggered

  • New EC2 instances were launched automatically

  • Instance count increased without manual intervention


✅ Final Outcome

  • Auto Scaling Group successfully scaled out

  • Scaling was triggered purely by CloudWatch CPU metrics

  • The setup demonstrated real-time, automated infrastructure scaling


🧠 Key Learnings

  • Auto Scaling is a core part of high availability and performance

  • CloudWatch metrics directly drive scaling decisions

  • Target tracking policies simplify scaling configuration

  • Stress testing is an effective way to validate scaling behavior

  • Detailed monitoring improves scaling responsiveness


📎 Conclusion

This hands-on lab helped me understand how Amazon EC2 Auto Scaling works in real-world scenarios.
By combining CloudWatch metrics with target tracking scaling policies, infrastructure can automatically adapt to workload changes, improving both reliability and efficiency.

I’ll continue practicing similar AWS labs to strengthen my cloud fundamentals through real implementations.

More from this blog

Sam's blog

56 posts