CI/CD Pipeline using AWS CodeCommit, Codebuild, CodeDeploy and CodePipeline
Published: 2024-01-26 07:19:26

---
title: CI/CD Pipeline using AWS CodeCommit, Codebuild, CodeDeploy and CodePipeline
published: true
date: 2023-12-28 12:47:51 UTC
tags: 
canonical_url: https://arjunmenon.hashnode.dev/cicd-pipeline-using-aws-codecommit-codebuild-codedeploy-and-codepipeline
---

## Introduction

Welcome to this comprehensive guide where we'll walk through the process of creating a CI/CD pipeline for deploying a Todo List web app using AWS DevOps services. This tutorial is designed to be beginner-friendly, providing detailed steps for setting up CodeCommit, CodeBuild, CodeDeploy, and CodePipeline. We'll be installing Nginx and deploying a Todo List web app on an EC2 instance.

## Code

All the required code is available at [this repository](https://github.com/ArjunMnn/AWS-devops-cicd.git).

## Step 1: Setting Up CodeCommit

1. **Create a CodeCommit Repository:**

2. **Create IAM User and Generate Credentials:**

3. **Clone Repository Locally:**

4. **Create Project Files:**

```
git add .git commit -m "Initial commit"git push origin main
```

## Step 2: Configuring CodeBuild

1. **Create a Build Project:**

```
# buildspec.yamlversion: 0.2phases: install: commands: - echo Installing Nginx... - sudo apt-get update - sudo apt-get install nginx -y build: commands: - echo Build started on `date` - cp index.html /var/www/html/ - cp styles.css /var/www/html/ - cp app.js /var/www/html/ - cp appspec.yml /var/www/html/ post_build: commands: - echo Restarting Nginx...artifacts: files: - index.html - appspec.yml - scripts/** - app.js - styles.css
```

1. **Configure Artifacts:**

2. **Run the Build:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703765629394/c269ddde-563a-48b6-897b-1bd52c5fc8a7.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703765654228/b8822dc5-3267-41dd-ad08-36a364c4ab57.png)

## Step 3: Implementing CodeDeploy

1. **Create CodeDeploy Application:**

2. **Create Deployment Group:**

3. **Install CodeDeploy Agent on EC2 Instance:**

```
#!/bin/bash # This installs the CodeDeploy agent and its prerequisites on Ubuntu 22.04. sudo apt-get update sudo apt-get install ruby-full ruby-webrick wget -y cd /tmp wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/releases/codedeploy-agent_1.3.2-1902_all.deb mkdir codedeploy-agent_1.3.2-1902_ubuntu22 dpkg-deb -R codedeploy-agent_1.3.2-1902_all.deb codedeploy-agent_1.3.2-1902_ubuntu22 sed 's/Depends:.*/Depends:ruby3.0/' -i ./codedeploy-agent_1.3.2-1902_ubuntu22/DEBIAN/control dpkg-deb -b codedeploy-agent_1.3.2-1902_ubuntu22/ sudo dpkg -i codedeploy-agent_1.3.2-1902_ubuntu22.deb systemctl list-units --type=service | grep codedeploy sudo service codedeploy-agent status
```

1. **Create appspec.yaml and Scripts:**

appspec.yaml:

```
# appspec.yamlversion: 0.0os: linuxfiles: - source: / destination: /var/www/html/hooks: AfterInstall: - location: scripts/install_nginx.sh timeout: 300 runas: root ApplicationStart: - location: scripts/start_nginx.sh timeout: 300 runas: root
```

install\_nginx.sh

```
# scripts/install_nginx.sh#!/bin/bashapt-get updateapt-get install nginx -y
```

start\_nginx.sh

```
# scripts/start_nginx.sh#!/bin/bashservice nginx start
```

1. **Build and Deploy:**

2. **Configure EC2 Role:**

3. **Restart CodeDeploy Agent:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703765608441/a886524c-7b22-44f4-8a39-f83a0d47ff27.png)

## Step 4: Setting Up CodePipeline

1. **Configure CodePipeline:**

2. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703765497088/80f2748d-f92c-48da-bff9-ef683808fd25.png)

3. **Create Pipeline:**

4. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703765984454/1767a1b5-faa9-4012-ab97-7c89ca7555ad.png)

5. **Test the Web App:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703765580343/0fe7a58a-db3d-4323-b6a4-341c2a2e108d.png)

## Conclusion

Congratulations! You've successfully set up a CI/CD pipeline for deploying a Todo List web app using AWS DevOps tools. This tutorial has covered each step in detail, providing you with a solid foundation for implementing similar projects in the future.

Follow me on [**LinkedIn**](https://www.linkedin.com/in/arjunmenon-devops/).

Checkout my [**GitHub**](https://github.com/ArjunMnn) profile.