DEV Community

Cover image for Automating The Deployment Spring Boot Deployment with AWS
Suraj
Suraj

Posted on

Automating The Deployment Spring Boot Deployment with AWS

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

image

  1. 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.
  2. 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.
  3. 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

image

Step 2: Elastic Beanstalk Configuration

Create your Elastic Beanstalk environment with these configurations:

image

  • Give it the Application name And the Domain Name and also check the availability.

image

  • Select Java 17 as the platform

image

  • Upload your initial .jar file and set version to 1

image

  • Configure service access settings:
    • Set up service role
    • Configure EC2 key pair
    • Set up AWS Elastic Beanstalk profile

image

  • 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 .

image

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

image

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:

image

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 :

image

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

image

  • Now chose the Custom build pipeline

image

  • Now give the pipeline a name and leave all the setting default and click on the next.

image

  • Now Select the provider which GitHub in my case using OAuth.

    After Authenticating chose the Repository name and the branch and click on next.

image

  • Now select the Other build providers and create a new project:

image

Give the project name:

image

After that chose the buildspec.yml options and click on the create code pipeline.

image

  • After that choose it will redirect you to the same page and just click on the next step:

image

  • Now the in the test stage choose the provder AWS CodeBuild and the project name and continute:

image

  • Now in the deploy stage choose the provider as AWS Elastic Beanstalk ,

    Region, Application Name and the Environment Name.

image

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

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 .

image

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)

image

image

7. Common Challenges and Solutions

Database Connection Issues:

  • Problem: Build failures due to communication link issues
  • Solution: Implement H2 in-memory database for testing

JAR File Naming:

  • Problem: Deployment failures due to JAR file mismatches
  • Solution: 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!

Top comments (1)

Collapse
 
nevodavid profile image
Nevo David

Nice, having everything spelled out like this honestly makes my life a ton easier when I get stuck on AWS stuff.