DEV Community

Cover image for CICD in AWS using CodePipeline and EBS
Sreekesh Iyer for AWS Community Builders

Posted on • Originally published at blog.sreekeshiyer.live

CICD in AWS using CodePipeline and EBS

The Cloud has made a lot of things simpler for developers. In this thread, let's explore how easy it is to set up a CICD Pipeline in AWS using GitHub, AWS CodePipeline and Elastic Beanstalk.

What is CI/CD?

Image Representation of CICD

CI/CD is the combined practice of continuous integration (CI) with continuous delivery or continuous deployment (CD). The purpose of CI/CD is to allow developers and teams to deliver code changes more frequently and reliably.

The reference to the word pipeline is to explain how all of these processes are executed in a sequence, one after the other. The key to CI/CD is automation. The process can be more and more efficient if there is not a lot of manual involvement. It is crucial to have an efficient pipeline when you're dealing with large codebases in production since a lot of changes are made at different parts of an application.

Prerequisites

  • An AWS Account (preferably Free Tier so that you are not charged for using cloud infrastructure)

Tools Used

  • GitHub
  • AWS CodePipeline
  • AWS Elastic Beanstalk

For this demonstration, we'll use a sample PHP application and deploy it to Elastic Beanstalk.

Creating a Deployment Environment in Elastic Beanstalk

Beanstalk Dashboard

Open up Elastic Beanstalk in the AWS Console and click on Create Application.

Beanstalk App Configuration
Give a name to your application, choose PHP for the platform and Sample Application for your code type. Now, click on Create Application.

Wait for a minute, while Beanstalk creates a sample environment for you to deploy your application. By default, it creates an EC2 instance, a security group, an Auto Scaling group, an Amazon S3 Bucket, Amazon CloudWatch alarms and a domain name for your application.

App Status after creation
Visiting the website

You can click on the URL to visit the application. You'll get a custom PHP welcome page by default.

Getting your sample code

Screenshot of the GitHub repository

A sample application is provided in a tutorial for creating a simple pipeline in the AWS Documentation. You can either upload those files to your GitHub repository or simply fork my GitHub repository here.

Since we are using GitHub as the source, we do not need the scripts folder, so you can delete it if you want. The scripts folder can come in handy if you are using Amazon S3 as the source for your application :)

Creating a CodePipeline

CodePipeline Dashboard

Open up the CodePipeline Dashboard. In this step, we will create a simple pipeline where we specify our GitHub Repository for the source code and deploy the code to the Beanstalk app we just created.

  • Step 1

Pipeline Setup 1

Enter a name for your pipeline and allow AWS to create a service role for this pipeline.

  • Step 2

Pipeline Setup 2
Create a Connection to Connect your pipeline to GitHub.

Authorizing AWS Connector for GitHUb
Ideally, you should only allow access to the specific GitHub Repository you're currently using.

Adding Source Information

After the connection, choose the repository and the branch and go with the default CodePipeline for Output artifact format.

  • Step 3 Deploy Stage

Skip the build stage (since we do not have any build command) and fill in the Beanstalk application details in the Deployment Stage and lastly, review the data and click on Create Pipeline.

View Pipeline Progress

Viewing Pipeline progress

Wait for a few minutes while the Pipeline is executed and you can see that the process was completed. You can click on AWS Elastic Beanstalk which takes you back to the Beanstalk application we created. Now, if you click on the URL, you can see that our application is successfully deployed.

Visiting the App

Congratulations, we just deployed our application to AWS Elastic Beanstalk via a pipeline.

Make Changes to re-run the pipeline

Viewing the changes on GitHub

Open up the pipeline repository on GitHub and make some changes in the index.html file using the default GitHub text editor.

Observing changes on CodePipeline

After making the changes, quickly switch back to the pipeline and observe the changes. You can notice that the pipeline is being re-executed on your new commit.

Visiting updated app

Once the pipeline execution is complete and successful, go back to the website.
As you can see, our changes were immediately reflected in our application and we didn't have to do anything extra for it.

You can take this to the next level, where you deploy your Node.js or Python projects to Beanstalk, set up Tests, and run them on every new commit to your production branch.

Recommended Cleanup

Deleting the Pipeline
Deleting the Beanstalk App

It is good practice to clean up/delete/terminate all services you have used on AWS (on any Cloud really) so that you are not charged in the future.

Firstly, delete your CodePipeline. Then, go to the Elastic Beanstalk Dashboard and delete your Application. This will also delete and terminate all other services used by the application.

This was a small demonstration of CICD in AWS. I hope you liked it. If you have used AWS CodePipeline before, do share your experience.

Thank you for reading :)

Top comments (0)