DEV Community

TechEazy Consulting
TechEazy Consulting

Posted on

Deploy a Spring Boot App on AWS EC2 with Load Balancer (Step-by-Step Guide)

๐ŸŒ 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
Enter fullscreen mode Exit fullscreen mode

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:

  1. Go to AWS Console โ†’ EC2 โ†’ Launch Instance
  2. OS: Ubuntu Server 24.04 LTS (Free Tier eligible)
  3. Instance type: t2.micro
  4. Key Pair: Create/choose one (for SSH access)
  5. 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>
Enter fullscreen mode Exit fullscreen mode

Install Java:

sudo apt update
sudo apt install openjdk-21-jdk -y
Enter fullscreen mode Exit fullscreen mode

Upload your app using scp:

scp -i your-key.pem app.jar ubuntu@<EC2_PUBLIC_IP>:/home/ubuntu/
Enter fullscreen mode Exit fullscreen mode

Run the app in the background:

sudo nohup java -jar app.jar > app.log 2>&1 &
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

  1. Go to EC2 โ†’ Load Balancers
  2. Click Create Load Balancer โ†’ Application Load Balancer
  3. Name: springboot-alb
  4. Scheme: Internet-facing
  5. VPC: Use default VPC
  6. Select AZs: Pick where your EC2s are running
  7. 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
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Welcome to Adaptation Controller - Techeazy
Enter fullscreen mode Exit fullscreen mode

โœ… 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)