0% found this document useful (0 votes)
15 views

Complete AWS CI_CD _ Deploy Spring Boot to ECS Using CodeBuild & CodePipeline From Scratch _ by Trinadh Rayala _ Medium

This article provides a step-by-step guide for deploying a Spring Boot application to AWS ECS using AWS CodeBuild and CodePipeline. It outlines the process of creating a Docker image, pushing it to AWS ECR, and automating the CI/CD pipeline. The guide emphasizes the use of a buildspec.yaml file for CI and the creation of a CodePipeline for deployment automation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Complete AWS CI_CD _ Deploy Spring Boot to ECS Using CodeBuild & CodePipeline From Scratch _ by Trinadh Rayala _ Medium

This article provides a step-by-step guide for deploying a Spring Boot application to AWS ECS using AWS CodeBuild and CodePipeline. It outlines the process of creating a Docker image, pushing it to AWS ECR, and automating the CI/CD pipeline. The guide emphasizes the use of a buildspec.yaml file for CI and the creation of a CodePipeline for deployment automation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Open in app Sign up Sign in

Search Write

Complete AWS CI/CD | Deploy


Spring Boot to ECS Using CodeBuild
& CodePipeline From Scratch
Trinadh Rayala · Follow
4 min read · Jul 22, 2024

33 1

Hello! In this article, I will guide you through the step-by-step process of
deploying your Spring Boot (Java) application to AWS ECS (Elastic Container
Service). By the end of this article, you will be familiar with CI (Continuous
Integration) using AWS CodeBuild and CD (Continuous Deployment) using
AWS CodePipeline.
Spring Application to AWS Deployment Overview

Points Involved:
1. Create the Docker Image for your application

2. Push the image to the AWS ECR (Elastic Container Registry)

3. Build and Deploy the application in AWS ECS (Elastic Container Service)

Note: Steps 2 and 3 can be automated for CI & CD.

CI can be automated using AWS CodeBuild.

CD can be automated using AWS CodePipeline.

How does AWS CodeBuild know the steps to create the image
and push it to AWS ECR?
We provide a buildspec.yaml file, which contains the steps guiding AWS
CodeBuild for CI (Continuous Integration).
Step-by-Step Process:

Step 1: Build the Spring Boot Application

spring boot app

Step 2: Create the Docker Image


1. Create a Dockerfile to dockerize your app.

2. Push the Docker Image to AWS ECR

Create an AWS ECR repository from the AWS Management Console (e.g.,
trinadh-registry ).
Step 3: Automate Steps 1 and 2 with AWS CodeBuild
Define the steps in the buildspec.yaml file, which has three phases:

1. Pre-build:

Commands for Maven clean, generating the JAR file, ECR repository URI, login
credentials, CodeBuild commits, and image tags.

2. Build:

Commands for building and tagging the Docker image.

3. Post-build:

Commands for pushing the image to ECR with the registry name.

Provide the buildspec.yaml file to AWS CodeBuild to execute the defined steps.
Step 4: Create the AWS CodeBuild Project
Open AWS CodeBuild in the AWS Management Console.

Create a project in CodeBuild and provide the necessary details and


permissions.

Attach the newly created ECR repository to AWS CodeBuild.

AWS CodeBuild will push the Docker image to AWS ECR ( trinadh-
registry ).

Provide the location of the buildspec.yaml file in your GitHub repository.

Start the build, and AWS CodeBuild will read the buildspec.yaml file and
execute the steps to create and push the Docker image to ECR.

By this step, the CI process is complete. The Docker image is successfully


pushed to the ECR registry using AWS CodeBuild.

code build for CI


docker image registry

complete pre_build, build, post_build deployment process


codeBuild project

Step 5: Create the AWS ECS Environment


1. Create the Task Definition:
Provide container details to load the image from the container.
Ensure to give the listening port (e.g., 8080).

2. Create the Cluster:


After creating the cluster, map the task to the cluster by creating a service
(recommended) or directly map the task to the cluster.

3. Add Service to the Cluster:


Map the service and provide rules like networking and security groups.

4. Run the Task Definition from the Service:


The application will run in AWS ECS after a successful build and
deployment.

Step 6: Create the AWS Code Pipeline


As part of creating an AWS CodePipeline, we need to automate the build and
deployment process. Here’s how we can set up the necessary stages in the
AWS console:

1. Source: Specify where the code source is coming from (e.g., GitHub).
2. Build: Use AWS CodeBuild as the build tool.
3. Deploy: Deploy the changes to AWS ECS.

Steps to follow:
1. Define the pipeline name.
2. Add source stage: Define the source code location (e.g., GitHub repository).
3. Add build stage: Specify AWS CodeBuild as the build tool.
4. Add deploy stage: Define the deployment destination as AWS ECS.

cluster map tasking


Continuous CI/CD

test api
swagger UI

build flow
Overview:
As a developer focusing on CI/CD, your primary task is to write code and
push changes to your repository. Once the changes are committed, the CI/CD
pipeline will automate the entire process: building the code, generating the
image, pushing it to AWS ECR, and deploying the latest image to AWS ECS.
This setup ensures that after the initial infrastructure configuration, you
only need to push code changes, and the AWS CodePipeline and AWS
CodeBuild will handle the rest.

Thank you for reading my article. I’d love to hear your suggestions for
improvements, so please share your thoughts in the comments section.

Code : git

Thank you
-Trinadh Rayala

Spring Boot AWS DevOps Deployment Software Development

You might also like