Deploying Spring Boot on AWS Elastic Beanstalk

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.

Deploying Spring Boot on AWS Elastic Beanstalk

🧰 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:

Build the JAR:

This creates target/your-app.jar.

🛠️ Step 2: Install EB CLI and Initialize

Install Elastic Beanstalk CLI:

Initialize Beanstalk in your project directory:

Select your region (e.g., us-east-1)

Choose platform: Java

Enable CodeCommit integration (optional)

🌱 Step 3: Create Beanstalk Environment

This creates:

  • EC2 instance
  • Load balancer
  • Auto-scaling group
  • CloudWatch monitoring
  • Logs, config, and health monitoring

You’ll get a URL like:

📦 Step 4: Configure Spring Boot for Beanstalk

Elastic Beanstalk looks for Procfile or uses default Java entrypoint.

📄 Create Procfile

📄 Optional: Add application.properties

Elastic Beanstalk expects Java apps to listen on port 5000.

Or let Spring Boot auto-bind:

⚙️ Step 5: Deploy Your App

Deploy using EB CLI:

To open the app:

You should see:

🔧 Step 6: Environment Variables

Set env variables:

Spring Boot picks them up automatically if defined like:

📈 Step 7: Logs & Monitoring

Get logs via CLI:

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:

Or add CI/CD integration using:

  • GitHub Actions
  • AWS CodePipeline
  • Jenkins

✅ Benefits of Elastic Beanstalk

FeatureDescription
Fully managed platformNo need to manage EC2, ALB, ASG manually
Zero-downtime deploymentsBuilt-in rolling deploys with health monitoring
Environment cloningEasily create staging/prod parity
Auto-scalingScales app based on traffic
Simplified logs/monitoringIntegrated 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.