# 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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210057789/d3df0b18-f310-4ad5-86a7-4d4582185b3e.png align="center")

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](https://github.com/Suraj-kumar00/aws-springboot-ecommerce)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210428999/9e19cfa0-8600-47fc-acc2-a12e0b714f50.png align="center")

## Step 2: Elastic Beanstalk Configuration

Create your Elastic Beanstalk environment with these configurations:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210502553/bc5ebd72-c6d4-474d-a3a6-9ab65e6ad0c3.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210556695/f0adb98d-25ba-4138-b509-84f0f002a7fb.png align="center")

* Select Java 17 as the platform
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210573609/941ead8c-fc9a-4ce9-953d-1b55d119ff68.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210618029/6fa4afdf-4834-4f05-95be-37f613429fbe.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210737377/0bd2a7a0-b2f5-4677-9c1c-bdaaa865ca5f.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210804843/b5ba02f1-b68e-4125-8297-a28be6468be0.png align="center")

## Step 3: Database Configuration

Choose the:

* VPC ( In my case I’m choosing default)
    
* Choose Instance subnets
    
* Choose Database subnets
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210878259/fdf642a3-2bca-4c47-820a-96227acd7026.png align="center")

For the database setup:

* Enable the RDS database integration
    
* Configure database username
    
* Set secure database password
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746210902138/124ed956-9008-4f25-b7fb-512180c6edc4.png align="center")

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:
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211073643/e35b15c7-9c10-4e3c-899b-360a948de513.png align="center")

Other then that leave all the settings defalut and go to the next step.

* Now choose the system as Basic:
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211123767/7c179416-fb98-461c-8421-25220eef83b6.png align="center")

* And leave all the setting as it is but change the `ENVIRONMENT VARIABLES` :
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211211038/09f149ba-f96a-4584-bb59-84752ca9e84b.png align="center")

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
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211342070/f7dcd00b-4795-4e8e-91de-032c87108ec9.png align="center")

* Now chose the Custom build pipeline
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211479040/0e4fa49a-f8c4-43da-91a5-546a6273326a.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211597079/c728461c-e0f2-4b1d-beb5-05a5a692a72c.png align="center")

* Now Select the provider which **GitHub** in my case using OAuth.
    
    After Authenticating chose the `Repository name and the branch` and click on next.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211625024/87c8bf51-1027-4325-a695-c31af7dafb74.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211651756/a477877d-fb8e-4642-ae5c-5689a8479705.png align="center")

Give the project name:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211697306/3544d53b-73d8-47b7-abdf-9bd66584043e.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211810285/94e346ee-19d9-4741-a340-b9b07ab6da9f.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211862356/81e26f85-744f-468d-a054-2ec85b7743f4.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211912816/92537d15-af8f-408b-a779-0dac9d362a3f.png align="center")

* Now in the deploy stage choose the provider as `AWS Elastic Beanstalk` ,
    
    Region, Application Name and the Environment Name.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211943547/3be47134-b8b1-4869-b620-a4cfbc115d6b.png align="center")

### Essential Configuration Files

Add this `buildspec.yml` to your project root:

You should change the `.jar` because you name could be different.

```yaml
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` .

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746211991366/17050a28-cba3-4edf-84ec-891674f377d6.png align="center")

## 6\. Result:

**The Application was deploy on this URL:** [http://aws-springboot-ecommerce.ap-south-1.elasticbeanstalk.com/](http://aws-springboot-ecommerce.ap-south-1.elasticbeanstalk.com/) (This will not work now as I deleted the steup)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746212068466/7d7b760b-206c-4240-9470-e35f1b4094a1.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746212116114/558468d8-81f9-43c8-a154-758b662e6bd8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746212083821/3abfbf67-a0e6-4721-85bd-a8b918e58093.png align="center")

## 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!
