Scaling Spring Boot with Auto Scaling Group (ASG) + Elastic Load Balancer (ELB)
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).
- Go to EC2 Dashboard β Instances
- Select an EC2 instance where your Spring Boot app is running
- From Actions β Image and Templates β Create Image
- Name it:
springboot-ami - 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.
Go to EC2 β Auto Scaling Groups β Create Auto Scaling Group
Under Launch Template, click Create new launch template
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)
- Name:
Add User Data (to auto-start the app):
#!/bin/bash
cd /home/ubuntu
sudo nohup java -jar app.jar > app.log 2>&1 &
- Click Create Launch Template β
βοΈ Step 3: Create Auto Scaling Group (ASG)
- Back to Auto Scaling Group creation
- Name:
springboot-asg - Select the Launch Template you just created
- 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
On Load Balancer settings:
- Attach to existing Load Balancer
- Select your Spring Boot Target Group (8080)
- Enable ALB health checks for reliability
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