fbpx Skip to content

Streamlining CI/CD Process with AWS CodePipeline


Continuous Integration/Continuous Deployment (CI/CD) is a set of software development practices that involves automating the process of integrating, testing, and deploying code changes to production. CI/CD pipelines have become the industry standard practice in modern software development, allowing organizations to deliver software faster and with higher quality.

Continuous Integration (CI) refers to integrating code changes into a shared repository such as GitHub, building the application, and testing it automatically, ensuring that the code is error-free and ready to be deployed. The aim is to catch any conflicts and errors early in the development phase. Continuous Delivery (CD) takes a step further and deploys these changes to a development or production environment. The goal is to deliver the application to the end user fastest and shorten the feedback loop.

The Benefits of CI/CD

Here’s a closer look into the benefits of CI/CD and why they have become the industry standard process.

    1. Short release time: Automating the process of integrating and deploying code changes allows quicker and more frequent releases, enabling faster time-to-market and the ability to respond to user feedback and change requirements more efficiently.
    2. Early detection of issues: By integrating and testing code changes regularly, CI/CD helps catch bugs, errors, and conflicts early in the development process, reducing the risk of issues reaching production.
    3. Increased collaboration: CI/CD ensures collaboration among team members by encouraging regular integration of code changes and resolving conflicts early. This leads to better communication, coordination, and teamwork among developers.
    4. Improved software quality: By automating testing and deployment, CI/CD helps ensure that only high-quality, thoroughly tested code reaches production, resulting in more stable, secure, and reliable software.
    5. Greater agility and innovation: CI/CD enables teams to quickly adapt to changing requirements and market conditions, promoting innovation and the ability to improve the software product continuously.

Demo – AWS CodePipeline for a Java Web app – Tomcat

Several CI/CD tools are available today, such as Jenkins, GitHub Actions, GitLab CI/CD, CircleCI, Bamboo, Azure DevOps, etc., each having its strengths and weaknesses. In this blog, we will use AWS CodePipeline, which integrates well with other AWS services, to create the CI/CD pipeline for a sample Java web app served by Tomcat. Feel free to read further; the process is similar for other web applications such as Node.Js, Django, .NET, and Laravel.


Before we begin, make sure you have the following prerequisites:

    • An AWS account with appropriate permissions to create and configure CodePipeline, CodeBuild, and Elastic Beanstalk resources.

We will use the following AWS services to create the pipeline:

    • AWS CodePipeline: A fully managed CI/CD service that automates application building, testing, and deployment.

    • AWS CodeBuild: A fully managed build service that compiles source code, runs tests, and produces software packages ready to deploy.

    • AWS Elastic Beanstalk: Elastic Beanstalk is a fully managed service that makes it easy to deploy, manage, and scale applications in the AWS Cloud. Based on our application environment, it will handle the provisioning and maintaining underlying infrastructure such as EC2, S3, and ASG.

Process Overview

CICD Process Overview                                                                                                                                                     CI/CD Process Overview


Flow Description

As the diagram above shows, the pipeline will be triggered automatically whenever a code changes in the source repository. AWS CodeBuild will then take this source code and build the application with applied configurations. This generates an application package (artifact) and stores it in S3 BucketFinally, in the deployment phase, Elastic Beanstalk will pull the artifact from S3 and launch the application from the bundle in the pre-defined environment. Additionally, CloudWatch produces the logs from CodeBuild that we can use for monitoring the build process. That concludes our flow.


Implementation Guide

Step 1: Create an Elastic Beanstalk Environment

    1. Open the AWS Management Console, navigate to the Elastic Beanstalk service, and click the “Create application” button. This will launch a configuration wizard.
    2. In the first step, choose the “Web Server environment” as the environment tier.
    3. Now, you can select the appropriate options for our application, such as platform, platform version application code source, and presets. We will go will the “Single Instance” preset as it is free tier eligible.



Elastic Beanstalk Configuration

Elastic Beanstalk Configuration
                                                                                      Elastic Beanstalk Configuration

           For our sample application: we have the following settings:

            Application name: ci-cd-demo
            Environment name: Cicddemo-env
            Platform: Tomcat 8.5
            Platform Version: 4.3.7

            4. Next, you can configure service access. Here, we will create a new service role. Optionally, you can add EC2 key pair to access EC2 servers deployed by Elastic Beanstalk.

Configure Service Access

5. Next, we will use the default options and select “Skip to review.” You can set up networking (selecting custom VPCs, assigning Public IP to our EC2 instances) and create databases and tags. You can also choose the capacity of Auto Scaling Group and configure monitoring and logging through CloudWatch metrics.

6. Review the configurations and click the “Submit” button to create the Elastic Beanstalk environment.

Step 2: Create a buildspec.yml file for CodeBuild

The buildspec.yml file is a configuration file that defines the build steps for your application and is used by CodeBuild to execute the build process (we will see the use of CodeBuild later). In your source code repository, create a buildspec.yml file at the root level of your project directory. This file contains the build steps for your application, such as building and testing your code.

Here is a buildspec.yml file for our sample application:

version: 0.2
    - echo "Pre-Build Phase"
      - echo "Build Phase Started"
      - mvn clean package
      - echo "Build Succeded"
    - target/aws-ci-cd*/*
  discard-paths: yes

This buildspec.yml file specifies three build phases: build, test, and post_build. Using another web framework, such as Node.js, you can install your dependencies in the pre_build Stage. We build our maven package in the build stage, creating the build artifact in the target/aws-ci-cd directory. The artifacts section of the build specification file details where to store the artifacts and the format in which they should be stored.

By default, CodeBuild stores the build artifacts in an S3 bucket created and managed by CodeBuild. The S3 bucket is named with a prefix codepipeline-* followed by a unique identifier for the CodeBuild project. You can also configure the building project using a custom S3 bucket to store the build artifacts. In our case, target/aws-ci-cd*/*, the pattern will include files from the target directory that match the aws-ci-cd*/* pattern. Once the build process is complete, the resulting artifact files will be uploaded to the S3 bucket created by CodeBuild.

Build Artifact stored in S3          

We can customize the buildspec.yml file based on the application’s requirements, such as adding additional build steps, tests, or deployment instructions. If you have not already, commit and push the buildspec.yml file to your source code repository.

Step 3: Set up a CodePipeline

Let’s create a code pipeline that glues everything we have done and deploy our application to ElasticBeanStalk.

    1. Open the AWS Management Console, navigate to the AWS CodePipeline service, and click the “Create pipeline” button.
    2. Enter a pipeline name, and create a new service role.
    3. Next, in the Source Stage, select your source provider (GitHub v2), and choose the repository and branch you want to use for your application source code. You might need to create a connection to GitHub if you are doing this for the first time. Give a connection name and click “Install a new app” to install AWS Connector for GitHub. Once connected, ensure the change detection option is checked to trigger the pipeline from the source code change.

  1. Code Pipeline- Source Configuration 1
                                                                                                           Code Pipeline- Source Configuration 1

Code Pipeline- Source Configuration 2

                                                                                         Code Pipeline- Source Configuration 2

Code Pipeline- Source Configuration 3

                                                                                                 Code Pipeline- Source Configuration 3

             4. Next, select AWS CodeBuild as your build provider in the Build Stage, and select the “Create Project” option. Here, we will configure a CodeBuild project to compile the source code, run tests (if present), and produce a software package ready to deploy.

Code Pipeline- Build Stage Configuration

                                                                                          Code Pipeline- Build Stage Configuration

  • (Build Stage Continued): Enter the project name and choose a runtime environment for your build, such as Node.js, Java, or Python, and specify the build configurations. We will select the following formats.

Code Pipeline- Build Stage Configuration

                                                                                              Code Pipeline- Build Stage Configuration

    • (Build Stage Continued) : Remember, we created buildspec.yaml earlier? It comes into use here. We will choose the Use a buildspec file option to look for buildspec. yaml in our repository root by default. Make sure to rename it if you have any other name for the build spec configs.

      Optionally, you can configure additional build options such as webhook triggers, CloudWatch Logs, and S3 Logs. Review your project configuration, add environment variables (if any), select “Buid type” as Single build, and click the “Continue to CodePipeline.”

  5. In the Deploy Stage, select AWS Elastic Beanstalk as your deployment provider, and choose the environment we created in Step 1.

Code Pipeline- Deploy Stage Configuration

                                                                                     Code Pipeline- Deploy Stage Configuration

             6. Finally, review your pipeline configuration and click the “Create pipeline” button to create your pipeline.

            Optional: We can create multiple environments in Beanstalk, for instance, separate production and dev environments. To quickly simulate these, Go to Elastic Beanstalk>Environment>Cicddemo-env>Actions>Clone environment. We will name it Cicddemo-prod. After this, go to your pipeline, click ‘Edit’ and follow the instructions to Add Stage. 

(This may differ as per your project requirement, and it’s beautiful just to use one deployment environment)


Step 4: Test the CI/CD pipeline

Now that we have set up the entire CI/CD pipeline, it’s time to test it by changing your application source code and triggering a pipeline run.

    1. Make changes to your application source code, such as fixing a bug, adding a new feature, or updating a configuration file. Here, I will change the welcome message in /src/main/webapp/index.jsp to “Welcome to CI/CD!”
    2. Commit and push the changes to GitHub or your source repository. This will trigger the pipeline to run automatically.
    3. Open the AWS CodePipeline service, and navigate to your pipeline to see the status of different stages. Here, we have used two environments for deployment. You might only see one if you have not created and added a new Beanstalk environment to the pipeline.

CodePipeline - Process

                                                                                                       CodePipeline – Process

    4. CodePipeline will automatically start the build process in CodeBuild, compiling our source code, running tests, and producing a deployment package. Once the build is successful, CodePipeline will automatically deploy the application to Elastic Beanstalk according to the deployment settings.

    5. Monitor the pipeline run in the CodePipeline console, and check the build details from CodeBuild or Elastic Beanstalk environment events and logs for any errors or issues.

Elastic Beanstalk Environment

                                                                                                     Elastic Beanstalk Environment

                  6. Once the deployment is complete, we can access the application on the Elastic Beanstalk environment URL to verify that the changes have been successfully deployed.

Sample App Message

                                                                                                                         Sample App Message

That’s it! We have successfully set up a CI/CD pipeline on AWS using AWS CodePipeline, AWS CodeBuild, and Elastic Beanstalk. Now you can change the application source code, and CodePipeline will handle your entire CI/CD Pipeline.


Implementing a CI/CD pipeline is crucial in modern software development practices to ensure efficient and reliable application delivery.We explored AWS’s powerful tools like CodePipeline, CodeBuild, and Elastic Beanstalk, which can be easily integrated to set up a robust CI/CD pipeline on the cloud. By following these steps, you can easily automate the process of building, testing, and deploying your applications, saving time and ensuring consistent quality in your software releases.

Please make sure to regularly monitor and update your pipeline settings and configurations as needed to adapt to the changing requirements of your applications. Happy Deploying!


AWS CodePipeline: https://aws.amazon.com/codepipeline/

CodeBuild buildspec specification:

Official Hands-on: https://aws.amazon.com/getting-started/hands-on/continuous-deployment-pipeline/

Read also: AWS vs. Azure vs. Google Cloud.