DEV Community

Cover image for CI/CD Pipeline Hands-on | AWS Code Pipeline, Elastic Beanstalk, GitHub
Warda Liaqat
Warda Liaqat

Posted on

CI/CD Pipeline Hands-on | AWS Code Pipeline, Elastic Beanstalk, GitHub

Introduction

In this article we are going to see how to use AWS code pipeline to set up a a very simple CI/CD pipeline for your developments with three products:

  • AWS Code Pipeline
  • Elastic Beanstalk (EB)
  • GitHub

I already have written some article covering each and everything about CI/CD, Do have a look to previous articles to have a better understanding of this one.

  1. Why CI/CD? How was a life without CI/CD & how is it now?
  2. Getting intimate with CI/CD and CI/CD Pipeline

Contents:

Intro to AWS Code pipeline

AWS Code Pipeline is a fully managed continuous delivery service that helps you automate your release pipelines for fast and reliable application and infrastructure updates. Code Pipeline automates the build, test, and deploy phases of your release process every time there is a code change, based on the release model you define. This enables you to rapidly and reliably deliver features and updates. You can easily integrate AWS Code Pipeline with third-party services such as GitHub or with your own custom plugin. With AWS Code Pipeline, you only pay for what you use. There are no upfront fees or long-term commitments.

Image description

Architecture of Our Code Pipeline

We are going to deploy a code pipeline on AWS. Below is architecture of our pipeline

Image description

  1. We will be using sample node.js application located in the GitHub Repo.
  2. Setup a pipeline so, whenever we commit any changes to our code in GitHub it will trigger AWS code pipeline instance to kick-in and start deployment process
  3. Finally code pipeline will deploy our application to our target Web Server which will be setup in AWS Elastic Beanstalk which essentially means our code will live on EC2 instances behind the scene.

So, that's it very simple one stage pipeline.

  • Go to GitHub and host your application there.

Image description

Let’s start building our Pipeline

  • Login AWS console

Environment Setup

  • Go to elastic beanstalk

In a nutshell Elastic Beanstalk is just a way to deploy our resources to AWS. In this case it's gonna deploy resources to EC2 instances behind the scene. if this were a great prod application i may directly go to ec2 and set it up directly there just to have a little bit of more control but at the expense of little bit of control it allows us to deploy very quickly.
You will be landed to this page. Just click on Get started/create application

Image description

  • Name your application
  • Choose platform
  • I’ll go with the sample code. I’m not gonna upload our code because I want our pipeline to do it for us.
  • Click on create Application

Image description

  • It will take several minutes to create and you can see all the logs to get to know what’s happening.

Image description

  • It will be deployed successfully after some time with health status OK. It has also deployed sample application into that as well. We used ec2, s3 behind this but you really don’t look at that, we can see in the logs. Elastic beanstalk take care of provisioning of those resources for us.
  • One more thing you don’t need to install any package for your application, if Elastic beanstalk detects any package in our application it will automatically install for us. Everything about this process is very automatic where the convenience factor comes in.
  • So, just for the test if it’s working. EB gives us a URL at the top to test your running application

Image description

And there we go, our first application is running and our very first deployment was successful.

Image description

Set up Pipeline

  • Next step is to go to AWS pipeline and setup a pipeline for our application.
  • Go to the code pipeline from AWS management console.

Image description

  • Now go ahead and click on create pipeline.
    You will see 5 stages to complete in order to create your pipeline.

  • Step 1
    Choose pipeline settings

  • Step 2
    Add source stage

  • Step 3
    Add build stage

  • Step 4
    Add deploy stage

  • Step 5
    Review

Let's explore all 5 steps.

Step 1:

  • Just name your pipeline and leave all the settings as it is.
  • And click on next

Image description

Image description

Step 2

  • Detect option this is saying how you want to trigger your pipeline. Go with the default for better ease. Because default one is more event driven model.

Version 1:

Image description

Version 2:

Image description

Step 3

  • Build stage is optional so, we are going to skip it for this project.

Image description

Step 4

  • Deploy provider is elastic beanstalk which is our target.

Image description

Step 5

  • Then just review everything and click on create pipeline.
  • Now we can see pipeline has been created and now it’s deploying to elastic beanstalk.

Image description

  • It will take minute or two then we can verify if it’s been deployed.
  • Now go to EB by clicking the URL

Image description

  • You will see your app is running in browser

Image description

Testing Our Code Pipeline

Now let’s do some updates in your code from GitHub and see if our pipeline detect those changes and populate them automatically to our application that is running on Elastic Beanstalk.
You can update and commit your changes from directly GitHub or you can do it also by cloning your repo, updating your changes and them committing them locally.

Update changes in code from GitHub:

Image description

Update changes in code locally & then commit to online repo:

Image description

Image description

Image description

  • After updating your changes in code either from GitHub or Locally, when you'll go to your code pipeline you will observe that your pipeline is in action, It will detect changes and then update the source and will deploy changes to EB automatically.

Image description

Image description

  • When you observe that pipeline is successfully done then if you open/refresh the URL of your application in the browser you will observe that changes have been deployed successfully.

Image description

Conclusion

See, how code pipeline can make things easy for you when you are working on your development projects, now you don't have to manually write test cases after each change and update those changes manually. Code pipeline will handle all of that automatically for you. Now you just need to relax and focus on adding more new features to your application and do lots of advancements.

> Let me know what do you think about it or if you are already using Code Pipeline for your developments?

Connect with me:

LinkedIn
Instagram
Twitter

Top comments (0)