π Introduction
Deploying your application manually on AWS can be time-consuming and error-prone. You might face:
- Traffic distributed unevenly across instances β
- Manual setup of health checks and failover β
- Lack of scalability and high availability β
π Thatβs where EC2 + ELB (Elastic Load Balancer) deployment shines.
By the end, youβll understand how to deploy a Spring Boot app on multiple EC2 instances, set up an Application Load Balancer, and route traffic intelligently.
π Flow: Browser β ELB β EC2 Instances running Spring Boot
π Step 1: Prepare Your Spring Boot App
Before we touch AWS, package your Spring Boot project into a runnable .jar file:
mvn clean package
Youβll get something like app.jar in the target/ directory.
β
We assume the app runs on port 8080
β
Requires Java and Maven installed locally
β
Target is .jar deployment, not Docker
- We used the adaptive-ai-qms Spring Boot app as an example. But you can replace it with any web application and port according to app.
β‘ Step 2: Launch EC2 Instances
Letβs spin up two EC2 instances for our Spring Boot app:
- Go to AWS Console β EC2 β Launch Instance
- OS: Ubuntu Server 24.04 LTS (Free Tier eligible)
- Instance type: t2.micro
- Key Pair: Create/choose one (for SSH access)
- Configure Security Group:
- SSH (22) β Your IP
- HTTP (80) β Anywhere
- Custom TCP (8080) β Anywhere (for Spring Boot)
π― Launch two EC2 instances with the same configuration.
π Step 3: Install Java & Deploy Spring Boot App
SSH into both instances:
ssh -i your-key.pem ubuntu@<EC2_PUBLIC_IP>
Install Java:
sudo apt update
sudo apt install openjdk-21-jdk -y
Upload your app using scp:
scp -i your-key.pem app.jar ubuntu@<EC2_PUBLIC_IP>:/home/ubuntu/
Run the app in the background:
sudo nohup java -jar app.jar > app.log 2>&1 &
Breakdown:
-
nohup: Keeps process running after logout -
java -jar: Runs your Spring Boot app -
> app.log 2>&1 &: Logs output and runs in background
β
Now access your app via:
http://<EC2_PUBLIC_IP>:8080/api/adapt/welcome
Repeat for the second EC2 instance.
π Step 4: Create an Elastic Load Balancer (ALB)
Now weβll route traffic to both EC2 instances via a Load Balancer.
- Go to EC2 β Load Balancers
- Click Create Load Balancer β Application Load Balancer
- Name:
springboot-alb - Scheme: Internet-facing
- VPC: Use default VPC
- Select AZs: Pick where your EC2s are running
- Security Group:
- Create a new one:
springboot-sg - Inbound Rules: Allow HTTP (80) and SSH (22)
Listener Setup
- Protocol: HTTP
- Port: 80
Create Target Group
- Type: Instances
- Name:
springboot-tg - Protocol: HTTP
- Port: 8080
- Health check path:
/actuator/health/readiness
β
Register your two EC2 instances
β
Attach this Target Group to the Load Balancer
β
Click Create Load Balancer
Your ALB is now live and routing traffic.
π§ͺ Step 5: Test Your Setup
π― Go to Load Balancer β Description tab
π Copy the DNS name (e.g., springboot-alb-123456.ap-south-1.elb.amazonaws.com)
Visit:
http://<DNS_NAME>/api/adapt/welcome
Expected Output:
Welcome to Adaptation Controller - Techeazy
β
Confirms ELB is routing to healthy EC2 instances
β
Confirms Spring Boot app is working across both instances
π You can now explore:
- Manual deployment
- Creating AMIs
- Using Launch Templates with Auto Scaling
π― Conclusion
Youβve successfully:
β
Deployed a Spring Boot app on EC2
β
Set up a Load Balancer to route traffic
β
Configured health checks to ensure uptime
β
Created a production-ready architecture for web-scale apps
π Next, pair this setup with Auto Scaling Groups for true elasticity and high availability.
β 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.
β³ 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
Top comments (0)