๐ 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)