Skip to main content

Command Palette

Search for a command to run...

Scaling Spring Boot with Auto Scaling Group (ASG) + Elastic Load Balancer (ELB)

Updated
β€’4 min read

Deploying a Spring Boot app on multiple EC2 instances with an Application Load Balancer (ALB) works great βœ… But what happens when traffic spikes? Or if one EC2 instance crashes?

πŸ‘‰ That’s where Auto Scaling Groups (ASG) step in.

By the end of this guide, you’ll know how to:

  • Create an AMI of your Spring Boot app
  • Build a Launch Template
  • Configure an Auto Scaling Group (ASG)
  • Integrate it with your Application Load Balancer (ALB)
  • Auto-scale your application πŸš€

πŸ‘‰ Flow: Browser β†’ ELB β†’ ASG β†’ EC2 Instances running Spring Boot


πŸ”‘ Pre-requisite

From the previous blog, you should already have:

βœ… 2 EC2 instances with Spring Boot JAR deployed on port 8080
βœ… Application Load Balancer (ALB) setup with a Target Group


πŸ“¦ Step 1: Create an AMI (Golden Image)

We’ll use one existing EC2 as a base image (AMI).

  1. Go to EC2 Dashboard β†’ Instances
  2. Select an EC2 instance where your Spring Boot app is running
  3. From Actions β†’ Image and Templates β†’ Create Image
  4. Name it: springboot-ami
  5. Click Create AMI

⏳ Wait 8–10 minutes. This AMI will be the blueprint for new EC2s in the ASG.


πŸ“ Step 2: Create a Launch Template

Launch Template = Recipe to spin up new EC2s.

  1. Go to EC2 β†’ Auto Scaling Groups β†’ Create Auto Scaling Group

  2. Under Launch Template, click Create new launch template

  3. Fill details:

    • Name: springboot-template
    • AMI: Select My AMIs β†’ springboot-ami
    • Instance type: t3.micro
    • Key Pair: Same as before
    • Security Group: Must allow 22 (SSH), 80 (HTTP), 8080 (Spring Boot)
  4. Add User Data (to auto-start the app):

#!/bin/bash
cd /home/ubuntu
sudo nohup java -jar app.jar > app.log 2>&1 &
  1. Click Create Launch Template βœ…

βš™οΈ Step 3: Create Auto Scaling Group (ASG)

  1. Back to Auto Scaling Group creation
  2. Name: springboot-asg
  3. Select the Launch Template you just created
  4. Click Next

🌐 Step 4: Configure Network Settings

  • VPC β†’ Default VPC
  • Subnets β†’ Select available ones (where ALB exists)
  • Leave defaults β†’ Next

πŸ”— Step 5: Integrate with Load Balancer

  1. On Load Balancer settings:

    • Attach to existing Load Balancer
    • Select your Spring Boot Target Group (8080)
    • Enable ALB health checks for reliability
  2. Click Next


πŸ“Š Step 6: Set Group Size & Scaling Policy

Define scaling behavior:

  • Desired capacity β†’ 2 (start with 2 instances)
  • Minimum capacity β†’ 1
  • Maximum capacity β†’ 3

Add a scaling policy:

  • Policy type β†’ Target tracking
  • Metric β†’ ALB Request Count per Target
  • Target Group β†’ springboot-tg
  • Target Value β†’ 50 (scale out if >50 requests per instance)

βœ… Step 7: Review & Create

  • Double-check everything
  • Click Create Auto Scaling Group

Your ASG is now active πŸŽ‰


πŸ” Step 8: Verify Setup

  • Go to EC2 β†’ Instances β†’ You’ll see new instances launched by ASG
  • Open ELB β†’ Target Group β†’ Targets β†’ Should show healthy instances
  • Try terminating one instance manually β†’ ASG will auto-recreate it!

πŸ§ͺ Step 9: Load Test Your Setup

To simulate traffic for 5 mins:

ab -n 1000 -c 50 http://<ALB_DNS_NAME>/api/adapt/welcome

(Using ApacheBench or any load testing tool)

🎯 ASG will launch new EC2s automatically if traffic increases.


🎯 Final Result

You’ve successfully:

βœ… Created an AMI for your Spring Boot app
βœ… Configured a Launch Template
βœ… Built an Auto Scaling Group (ASG)
βœ… Integrated ASG with your Load Balancer
βœ… Enabled self-healing + scaling πŸš€

Now your app can handle failures and traffic surges without manual effort πŸ’ͺ


βœ… Next Steps πŸš€

Be interview-ready in the era of AI & Cloud β€” start your DevOps journey today!

πŸ’‘ YouTube won’t get you a job. Real projects + real internship certificate will.
πŸ”₯ AI is reshaping jobs. Don’t watch it happen, be part of it with DevOps & Cloud skills.
🎯 β‚Ή2000/month today = Dream job tomorrow. Secure your spot now.
⏳ Every month you wait, Cloud + AI jobs are being filled. Don’t miss out!
🌐 DevOps + AWS + AI = The skillset every recruiter is hunting for in 2025.

πŸ‘‰ Register now at TechEazy Consulting


More from this blog

TechEazy Consulting

34 posts