AWS Code PipeLine Continues Integration and Continues Deployment

Senthilkumar.P
7 min readSep 23, 2022

--

Introduction

  • AWS CodePipeline is a fully managed continuous delivery service that helps you automate your release pipelines for fast and reliable application and infrastructure updates.
  • CodePipeline 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 CodePipeline with third-party services such as GitHub or with your own custom plugin.

Benefits:

Rapid delivery

  • AWS CodePipeline automates your software release process, allowing you to rapidly release new features to your users. With CodePipeline, you can quickly iterate on feedback and get new features to your users faster.
  • Automating your build, test, and release process allows you to quickly and easily test each code change and catch bugs while they are small and simple to fix. You can ensure the quality of your application or infrastructure code by running each change through your staging and release process.
  • With AWS CodePipeline, you can immediately begin to model your software release process. There are no servers to provision or set up. CodePipeline is a fully managed continuous delivery service that connects to your existing tools and systems.

Configurable workflow

  • AWS CodePipeline allows you to model the different stages of your software release process using the console interface, the AWS CLI, AWS CloudFormation, or the AWS SDKs. You can easily specify the tests to run and customize the steps to deploy your application and its dependencies.

Easy to integrate

  • AWS CodePipeline can easily be extended to adapt to your specific needs. You can use our pre-built plugins or your own custom plugins in any step of your release process.
  • For example, you can pull your source code from GitHub, use your on-premises Jenkins build server, run load tests using a third-party service, or pass on deployment information to your custom operations dashboard.

How It’s Works:

Pipeline Flow

Application Deployment

CREATE CODE BUILD

For code build we must have below prerequisites,

1. Source code should be in GitHub

2. Create S3 Bucket

3. S3 Bucket to store Project output build

4. buildspec.yml file in project root directory

If once Project is ready to commit the code in GitHub Repository and configure AWS Code Build.

Go to AWS console and select code build service,

In code build service select “Create Project”

In Create Build Project page choose Project name and Description,

Under Source,

Select Source Provider as GitHub,

Map the GitHUB url

Under Primary source webhook events,

Choose Event Type as “PUSH”

Under Environment,

Select Environment image as Managed Image

Operating System as Ubuntu

Runtimes as Standard

Select service Role which we created In IAM for code build

Under Artefact’s,

Choose type as Amazon S3

è Choose Bucket name — our case bucket name is cicdangular. ** Proceeding this step we should have S3 Bucket ready**

  • In Name choose project name and Artifacts packaging as “Zip”

Now uncheck the cloudwatch logs and click “Create Build Project” and you can see code build project like below screen shot if everything is fine.

If Code Build is success we can see our project in S3 Bucket,

If we unzip the project from S3 we can see the project structure like below,

1. CicdPipeline folder contains project related files

2. Scripts Contains .sh files

3. appspec.yml file has operating system, files and hooks section information’s.

Refer Below GitHub Repository for more information on above three Snippets,

** Now We have completed CodeBuild and Project is also in S3 Bucket available for CodeDeploy **

Create CODE DEPLOY:

Go to code deploy service and choose “Create Application”

Under Create Application,

Choose Application name

Compute Platform as EC2/On-premises and then click Create Application

Click Create Deployment Group,

Under, Deployment group name,

Choose Deployment group name

Service Role as “code-deploy-role” which we created on IAM for code deploy

Deployment Type as “In-Place”

Under Environment Configuration,

Check “Amazon EC2 Instances” and select Key and value for our EC2 Instance. This Key and Value we have given while creating EC2 Instance.

Under Deployment Settings,

In Deployment configuration choose from drop down as “CodeDeployDefault.OneAtATime”

Uncheck the Load Balancer and click create deployment group.

Create Code PipeLine

Go to Pipeline Service and click “Create Pipeline”

Under Choose PipeLine settings,

Chose Pipeline name

Service role as “New Service Role”

Under Advanced settings, don’t do anything just proceed with defaults and click next

Under Add source stage,

Chose Source provider as GitHUB

Repository as GITHUB Project repository

Branch as Master

Change detect options as GitHub Webhooks(recommended) and then click next

Under Add Build stage,

Select Build provider as AWS CodeBuild

Region as Asia Pacific(Mumbai)

Project name “CODE BUILD PROJECT NAME” which we given while creating code build and click Next

Under Add Deploy Stage,

Choose Deploy Provider as AWS CodeDeploy

Region as Asia Pacific(Mumbai)

Application Name as Code Deploy Name which we given while creating Code Deploy

Deployment Group as Deployment Group Name which we given while creating Deployment Group

Click Next and click Create PipeLine. Now we have successfully create Pipeline.

  • If we once created the pipeline, the code build and code deploy is going to start immediately.
  • It has overall three stages,
  1. Source (Fetching Projects from GitHub Repository)

2. Code Build

3. Code Deploy to EC2 Instance

If all three stages passed it will show tick mark on middle of the right side and if we see in EC2 Instance our Application has deployed successfully,

Do SSH for EC2 Instance and check project under home/ubuntu/nodejs/

Install node modules in CicdPiepline folder in order to run our application,

If once npm installed, it looks like on below screen shot,

Now go to CiCdpipeline folder and run the application.

Either we can app.js or server.js

Our case we will run app.js like below command,

node app.js

Now our Application is running and if we hit our EC2 instance we can see like below,

--

--