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)