AWS Builder Center
Building an Automated CI/CD Pipeline on AWS Using CodePipeline, CodeBuild, and ECS

Building an Automated CI/CD Pipeline on AWS Using CodePipeline, CodeBuild, and ECS

A hands-on guide to building, testing, containerizing, and deploying a Java Spring Boot application on AWS. Explore how AWS CodePipeline, CodeBuild, Amazon ECR, ECS Fargate, and Docker work together to automate application delivery through a CI/CD workflow.

Building an Automated CI/CD Pipeline for Spring Boot on AWS

Introduction

Continuous Integration and Continuous Delivery (CI/CD) are essential DevOps practices that automate software building, testing, and deployment. Instead of manually building and deploying an application after every code change, a CI/CD pipeline creates a repeatable workflow.
In this project, I implemented an AWS CI/CD pipeline to build, test, containerize, and deploy a Java Spring Boot Student Management application using AWS CodePipeline, CodeBuild, Amazon ECR, and Amazon ECS with AWS Fargate.
The objective was to understand how AWS services work together to automate application delivery.

1. Understanding the Architecture

The application uses the following services:
Service
Responsibility
GitHub
Stores application source code
AWS CodePipeline
Orchestrates CI/CD stages
AWS CodeBuild
Builds, tests, and packages the application
Amazon ECR
Stores Docker container images
Amazon ECS with Fargate
Runs the deployed application
Amazon RDS for MySQL
Provides managed relational database storage
AWS IAM
Manages service permissions
Terraform
Defines AWS infrastructure as code
CI/CD Workflow:
GitHub → CodePipeline → CodeBuild → Maven Tests → Docker Build → Amazon ECR → Amazon ECS (Fargate)
The running Spring Boot application communicates with MySQL through its configured database connection.

2. Step 1: Prepare the Spring Boot Application

The project uses Java 21, Spring Boot, Maven, and MySQL.
The Student Management application supports basic CRUD operations: creating, viewing, updating, and deleting student records.
Before integrating AWS, I validated the application locally using Maven:
./mvnw clean verify
This executes the configured build verification and automated tests.
Concept: Continuous Integration helps identify application errors before code reaches the deployment environment.

3. Step 2: Containerize the Application Using Docker

Docker packages an application and its runtime dependencies into a portable container image.
I used a multi-stage Dockerfile with Maven for building the application and Java 21 JRE for running it.
The basic Docker workflow is:
docker build -t student-app:local .
docker run -p 8080:8080 student-app:local
The application also requires a reachable database with appropriate connection settings. Docker Compose can start the application and MySQL together for local testing.
Concept: Containerization provides deployment consistency across development, testing, and cloud environments.

4. Step 3: Configure AWS CodeBuild

AWS CodeBuild is a managed build service that executes commands defined in a  buildspec.yml  file.
My build configuration includes:
  1. Installing and validating the build environment.
  1. Starting MySQL for integration testing.
  1. Running Maven verification and tests.
  1. Building the Docker image.
  1. Running application smoke tests and persistence checks.
  1. Tagging and pushing the tested image to Amazon ECR.
A simplified build phase looks like this:
phases:
build:
commands:
- ./mvnw clean verify
- docker build -t student-app:local .
The complete project configuration includes additional test, registry authentication, and artifact-generation commands.
Concept: AWS CodeBuild provides automated and repeatable application builds without maintaining a dedicated build server.

5. Step 4: Store the Docker Image in Amazon ECR

Amazon Elastic Container Registry (ECR) provides managed storage for container images.
After the build succeeds, CodeBuild authenticates with ECR, tags the Docker image, and pushes it to the repository.
A typical image push follows this pattern:
docker tag student-app:local <ECR_REPOSITORY_URI>:v1
docker push <ECR_REPOSITORY_URI>:v1
In the project, the image tag is generated using source revision information and the CodeBuild build number.
I also used ECR image scanning to inspect container vulnerabilities. The recorded scan completed successfully with zero reported findings across the displayed severity categories.
Concept: A container registry stores versioned application images so the same build artifact can be deployed consistently.

6. Step 5: Deploy the Application Using Amazon ECS and Fargate

Amazon ECS is a container orchestration service, while AWS Fargate provides the compute capacity for running containers without managing EC2 instances.
The deployment workflow includes:
  1. Creating an ECS cluster.
  1. Defining the application's container configuration in a task definition.
  1. Creating an ECS service to maintain the desired number of tasks.
  1. Connecting the service to the required networking and database resources.
  1. Updating the ECS service when a new container image becomes available.
CodeBuild produces an  imagedefinitions.json  artifact containing the image URI. The ECS deployment action uses this artifact to update the application.
Concept: ECS manages container deployment and service availability, while Fargate removes the need to manage the underlying application servers.

7. Step 6: Automate Everything with AWS CodePipeline

AWS CodePipeline connects the individual delivery stages into a single automated workflow.
The pipeline contains three stages:
Source: Retrieves application code from GitHub.
Build: Uses CodeBuild to run tests, build the Docker image, push it to ECR, and generate deployment artifacts.
Deploy: Updates the ECS service using the newly published image.
In my implementation, the pipeline successfully completed all three stages.
This demonstrates an automated delivery process from source code to container deployment.

8. Deployment Validation and Monitoring

After deployment, I inspected the AWS console to verify the pipeline and running service.
The results included:
  • Successful Source, Build, and Deploy stages in CodePipeline.
  • An active ECS service with one running task.
  • Successful ECS deployment status.
  • CPU and memory utilization metrics.
  • A successfully stored and scanned container image in Amazon ECR.
These checks demonstrate the importance of validating application deployment instead of relying only on successful build output.

Conclusion

This project helped me understand how AWS DevOps services work together to automate the software delivery lifecycle.
The key learning was the separation of responsibilities: CodePipeline orchestrates the workflow, CodeBuild performs the build and tests, ECR stores the container image, and ECS with Fargate deploys and runs the application.
It also provided hands-on experience with Docker, Maven, AWS IAM, managed databases, and infrastructure configuration.
GitHub Repository:
Further improvements: Automated rollback, CloudWatch alarms, deployment notifications, and enhanced security testing.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article