How to Setup auto-deployment using CodeCommit, CodeDeploy, and CodePipeline

In this article, I will show you how you can set up an auto-deployment using CodeCommit, CodeDeployment, and CodePipeline. This is a routine job for DevOps to setup these pipelines for different projects. But before that, let’s discuss each of the services separately first.

What is CodeCommit

This is an AWS service that provides a GIT server on the cloud. So you can keep all your repositories in CodeCommit and do the continuous development over there. You can think CodeCommit as the alternative to GitHub or BitBucket. You can add unlimited Git Repositories in CodeCommit without any costs. AWS charges on the number of CodeCommit users and up to 5 users it is free of charge.

In CI/CD pipeline, codecommit acts as the continuous integration provider, where you manage your codebase via codecommit. Our next service is CodeDeployment.

What is CodeDeploy

AWS CodeDeploy is a fully managed deployment service that automates software deployments to a variety of computing services such as Amazon EC2, AWS Fargate, AWS Lambda, and your on-premises servers. AWS CodeDeploy makes it easier for you to rapidly release new features, helps you avoid downtime during application deployment, and handles the complexity of updating your applications.

What is CodePipeline

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.

Commands to install a web server in EC2

sudo yum update -y
sudo yum install -y httpd24 php72  php72-mysqlnd php72-mbstring
sudo yum install -y php72-mcrypt php72-zip php72-intl php72-gd
sudo service httpd start
sudo chkconfig httpd on
sudo groupadd www
sudo usermod -a -G www ec2-user
sudo usermod -a -G www apache
sudo chown -R ec2-user /var/www
sudo chgrp -R www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} +
find /var/www -type f -exec sudo chmod 0664 {} +
sudo chmod 0777 /var/lib/php/7.2/session
sudo service httpd restart
sudo yum install ruby -y
sudo yum install wget -y
cd /home/ec2-user
wget https://aws-codedeploy-eu-west-1.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent start

#appspec.yml file example given below

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/html/
permissions:
  - object: /var/www/html/
    owner: ec2-user
    group: www

Interested to learn more about linux? Visit my articles on Linux

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

This Post Has One Comment

Leave a Reply