Automating The Deployment Spring Boot Deployment with AWS CodePipeline and Elastic Beanstalk


In this comprehensive guide, I’ll walk through setting up a complete CI/CD pipeline using AWS CodePipeline to deploy a Spring Boot application to Elastic Beanstalk. Here's what we'll cover:
Tools Used
Tool | Role |
CodeCommit | Git repository for source code |
CodeBuild | Builds the Spring Boot app and outputs the .jar |
CodePipeline | Orchestrates source → build → deploy stages |
Elastic Beanstalk | Deployment environment |
Let’s understand the architecture diagram
Source (GitHub Repository)
The pipeline starts when a code change is pushed (commit) to your GitHub repository.
This event triggers the pipeline automatically — no manual deployment needed.
Build Phase (CodePipeline + CodeBuild)
AWS CodePipeline detects the commit and initiates the CI/CD process.
It hands over the code to AWS CodeBuild, which:
Builds the project (compiles the Spring Boot application).
Runs tests (unit/integration).
Returns the build status (success or failure) back to CodePipeline.
Deploy Phase (Elastic Beanstalk)
If the build is successful, CodePipeline proceeds to the Deploy stage.
It deploys the built Spring Boot application to AWS Elastic Beanstalk, a managed environment that handles infrastructure, load balancing, scaling, and app hosting.
Step-by-Step Follow-up:
Step 1: Repository Setup
First, create a GitHub repository for your Spring Boot project. This will serve as our source code repository.
GitHub Repository: https://github.com/Suraj-kumar00/aws-springboot-ecommerce
Step 2: Elastic Beanstalk Configuration
Create your Elastic Beanstalk environment with these configurations:
- Give it the Application name And the Domain Name and also check the availability.
- Select Java 17 as the platform
- Upload your initial .jar file and set version to 1
Configure service access settings:
Set up service role
Configure EC2 key pair
Set up AWS Elastic Beanstalk profile
- In initial case there’s no EC2 instance profile so just click on the view permission details and create the role according to that in AWS IAM Role .
Step 3: Database Configuration
Choose the:
VPC ( In my case I’m choosing default)
Choose Instance subnets
Choose Database subnets
For the database setup:
Enable the RDS database integration
Configure database username
Set secure database password
After that just click on next.
- Now in this step just choose the Security Group and we can edit it lated in the EC2 security group inbound rule for opening the custom ports:
Other then that leave all the settings defalut and go to the next step.
- Now choose the system as Basic:
- And leave all the setting as it is but change the
ENVIRONMENT VARIABLES
:
After that click on the next step.
At the last step just review all the configuration and submit it.
Step 4: Pipeline Setup
Create your AWS CodePipeline:
- Navigate to AWS CodePipeline and create a new pipeline
- Now chose the Custom build pipeline
- Now give the pipeline a name and leave all the setting default and click on the next.
Now Select the provider which GitHub in my case using OAuth.
After Authenticating chose the
Repository name and the branch
and click on next.
- Now select the
Other build providers
and create a new project:
Give the project name:
After that chose the buildspec.yml
options and click on the create code pipeline.
- After that choose it will redirect you to the same page and just click on the next step:
- Now the in the test stage choose the provder AWS CodeBuild and the project name and continute:
Now in the deploy stage choose the provider as
AWS Elastic Beanstalk
,Region, Application Name and the Environment Name.
Essential Configuration Files
Add this buildspec.yml
to your project root:
You should change the .jar
because you name could be different.
version: 0.2
phases:
install:
runtime-versions:
java: corretto17
pre_build:
commands:
- echo Build started on `date`
build:
commands:
- mvn clean install
artifacts:
files:
- target/Shopping_Cart-0.0.1-SNAPSHOT.jar
- Procfile
- .ebextensions/**/*
discard-paths: no
5. Pipeline Execution Flow Diagram
This is the execution result of the AWS Code Pipeline Taking the source, Building it and Deploying the new verion of the application to AWS Elastic Beanstalk
.
6. Result:
The Application was deploy on this URL: http://aws-springboot-ecommerce.ap-south-1.elasticbeanstalk.com/ (This will not work now as I deleted the steup)
7. Common Challenges and Solutions
Database Connection Issues:
Problem
: Build failures due to communication link issuesSolution
: Implement H2 in-memory database for testing
JAR File Naming:
Problem
: Deployment failures due to JAR file mismatchesSolution
: Maintain consistent artifactId naming across configurations
Best Practices
Key practices to follow:
Separate test and production configurations
Use environment variables for sensitive data
Implement proper proxy configuration
Add post-deployment hooks
Maintain consistent artifact naming
Implement proper error handling and logging
Thanks for reading - See you in the next one!
Subscribe to my newsletter
Read articles from Suraj directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Suraj
Suraj
I'm a Developer from India with a passion for DevOps ♾️ and open-source 🧑🏻💻. I'm always striving for the best code quality and seamless workflows. Currently, I'm exploring AI/ML and blockchain technologies. Alongside coding, I write Technical blogs at Hashnode, Dev.to & Medium 📝. In my free time, I love traveling, reading books