How to build a CI/CD Pipeline in AWS using CodeCommit, CodeDeploy, CodePipeline: Hands-on!
Trilochan Parida
Posted on June 3, 2020
This tutorial helps to continuous integration and continuous deployment of your application from the local system to your QA or Staging or Production server. So please follow the below steps to get it done.
Step-1: Install GIT and configure in your local system
Go to git-scm.com and download it to your system then install it. Then after you need to configure the GIT on the local system using below command.
$ git config - -global user.name “Trilochan Parida”
$ git config - -global user.email “tri***@gmail.com”
Step-2: Create CodeCommit repository ( YouTube )
- Go to CodeCommit service in the AWS console.
- Create a new repository with your project name.
- Copy the clone URL → Clone HTTPS.
Before clone to your local system, you need the credentials to access this repository, so let’s create that first.
Step-3: Create a new AWS IAM user and generate GIT credentials (YouTube)
- Add the user and create a group.
- Attach IAM policy “AWSCodeCommitFullAccess” and “AWSCodePipelineFullAccess”.
- Security Credentials → HTTPS GIT Credentials → Generate.
Step-4: GIT Clone (YouTube)
Using the above credentials, now we can clone the repository from AWS CodeCommit to the local system. And the command to clone is
$ git clone <URL>
As we are in AWS IAM service console so let’s create two Roles for future use in CodeDeploy and EC2 to access S3 artifacts.
Step-5: Create service Role for EC2 and CodeDeploy ( YouTube )
- Create an IAM role for CodeDeploy service and attach existing IAM policy “AWSCodeDeployRole”
- Create an IAM role for EC2 service and attach existing IAM policy “AmazonS3ReadOnlyAccess”
Step-6: Code push and understanding of appspec.yml ( YouTube )
Now we will put our application to that same folder which cloned from AWS. And here you have remembered to create an appspec.yml file to automate the code deployment. Here I will recommend watching my video to better understanding.
appspec.yml
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html/
Step-7: Set up an EC2 instance, install Nginx, and install CodeDeploy agent ( YouTube )
- Launch EC2 instance with default VPC, instance type would be t2.micro, select IAM Role that we had created in step-5 and add Tags with Key and value which will be used in CodeDeploy.
- Install Nginx
$ apt update
$ apt install nginx
- Install CodeDeploy agent
$ apt install ruby
$ apt install wget
$ wget https://aws-codedeploy-ap-south-1.s3.ap-south-1.amazonaws.com/latest/install //For Mumbai Region
$ chmod +x ./install
$./ install auto
Now you need to code deploy agent service for that use below command
$ service codedeploy-agent start
Step-8: Create an application in CodeDeploy ( YouTube )
- Go to CodeDeploy service console
- Create a new application with your application name and select compute platform to EC2/On-Premises
- Create deployment groups with name and deployment type is “in-place” and select environment configuration as Amazon EC2 instance with Key=Name and Value= “tag value of EC2”
Step-9: Create CodePipeline ( YouTube )
- Go to AWS CodePipeline service console
- Create a pipeline with a name and keep the default set up.
- Add Source Stage → Source provider: AWS CodeCommit → Select your repository → Select your branch → Detection option: CloudWatch Event
- Add Build Stage → Skip
- Add Deploy Stage → Deploy Provider: AWS CodeDeploy → Enter application name → EnterDeployment Group
Step-10: Test your application and watch the complete video
Go to your browser and type your IP. Congratulations!!! You have successfully deployed your code.
Posted on June 3, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.