AWS Elastic Beanstalk is one of the easiest ways to deploy and scale Spring Boot applications in the cloud—without managing infrastructure. With support for Java, Beanstalk handles provisioning, load balancing, scaling, and monitoring for you.
In this guide, you’ll learn:
- How to package your Spring Boot app for Elastic Beanstalk
- Create an environment using the AWS CLI and Console
- Configure health checks, environment variables, and logs
- Automate deployments using Git
All examples use com.kscodes.springboot.containers
as the base package.

🧰 Prerequisites
Make sure you have:
- A Spring Boot project (packaged as
.jar
) - AWS CLI installed and configured (
aws configure
) - EB CLI installed (
pip install awsebcli
) - An AWS account with IAM permissions
- Java 21 and Maven installed
🏗️ Step 1: Spring Boot Application
A minimal controller to test:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
package com.kscodes.springboot.containers; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/") public String index() { return "Hello from AWS Elastic Beanstalk!"; } } |
Build the JAR:
1 2 3 4 |
./mvnw clean package -DskipTests |
This creates target/your-app.jar
.
🛠️ Step 2: Install EB CLI and Initialize
Install Elastic Beanstalk CLI:
1 2 3 4 |
pip install awsebcli |
Initialize Beanstalk in your project directory:
1 2 3 4 |
eb init |
Select your region (e.g., us-east-1
)
Choose platform: Java
Enable CodeCommit integration (optional)
🌱 Step 3: Create Beanstalk Environment
1 2 3 4 |
eb create springboot-env --instance_type t3.micro |
This creates:
- EC2 instance
- Load balancer
- Auto-scaling group
- CloudWatch monitoring
- Logs, config, and health monitoring
You’ll get a URL like:
1 2 3 4 |
http://springboot-env.eba-xyz.us-east-1.elasticbeanstalk.com |
📦 Step 4: Configure Spring Boot for Beanstalk
Elastic Beanstalk looks for Procfile
or uses default Java entrypoint.
📄 Create Procfile
1 2 3 4 |
echo "java -jar target/your-app.jar" > Procfile |
📄 Optional: Add application.properties
1 2 3 4 |
server.port=5000 |
Elastic Beanstalk expects Java apps to listen on port 5000.
Or let Spring Boot auto-bind:
1 2 3 4 |
server.port=${PORT:5000} |
⚙️ Step 5: Deploy Your App
Deploy using EB CLI:
1 2 3 4 |
eb deploy |
To open the app:
1 2 3 |
eb open |
You should see:
1 2 3 4 |
Hello from AWS Elastic Beanstalk! |
🔧 Step 6: Environment Variables
Set env variables:
1 2 3 4 |
eb setenv SPRING_PROFILES_ACTIVE=prod DB_URL=jdbc:mysql://... |
Spring Boot picks them up automatically if defined like:
1 2 3 4 |
spring.datasource.url=${DB_URL} |
📈 Step 7: Logs & Monitoring
Get logs via CLI:
1 2 3 4 |
eb logs |
Enable enhanced monitoring and alarms via AWS Console:
- CPU, memory, disk
- Instance health
- Deployment status
🔄 Automate with Git Deployment
You can tie deploys to commits:
1 2 3 4 5 |
eb init --source eb deploy |
Or add CI/CD integration using:
- GitHub Actions
- AWS CodePipeline
- Jenkins
✅ Benefits of Elastic Beanstalk
Feature | Description |
---|---|
Fully managed platform | No need to manage EC2, ALB, ASG manually |
Zero-downtime deployments | Built-in rolling deploys with health monitoring |
Environment cloning | Easily create staging/prod parity |
Auto-scaling | Scales app based on traffic |
Simplified logs/monitoring | Integrated with CloudWatch |
📘 Summary
In this guide, you deployed a Spring Boot application on AWS Elastic Beanstalk using a JAR file and the EB CLI. You learned how to configure the environment, add a Procfile
, manage environment variables, and scale your application with zero downtime.
This is one of the simplest yet powerful ways to deploy Spring Boot apps in the cloud without worrying about the infrastructure layer.