# Day 51: Your CI/CD pipeline on AWS - Part 2 🚀 ☁(Jan 16, 2024)

## **🙏 Introduction:**

In this blog, we will deploy CI/CD pipeline on AWS using (CodeCommit, CodeBuild, CodeDeploy, CodePipeline & S3) tools, this is the part-2

## **🔶What is CodeBuild ?**

* AWS CodeBuild is a fully managed build service that compiles source code, runs tests, and produces software packages that are ready to deploy. With CodeBuild, you don’t need to worry about provisioning and managing your own build infrastructure. You simply provide your build project’s source code and build settings, and CodeBuild handles the rest.
    
* For example, if you have a web application that you want to deploy, you can use CodeBuild to compile your source code, run unit tests, and produce a deployable package. You can also use CodeBuild to build Docker images, run static code analysis, and more. CodeBuild integrates with other AWS services like CodePipeline, so you can easily automate your entire software release process.
    

## **🎯Task: 1**

1. ### **Read about Buildspec file for Codebuild**
    
    A Buildspec file is a YAML file that defines the build process for your CodeBuild project. It contains a series of commands that CodeBuild will execute to build and package your application.
    
2. ### **Create a simple index.html file in CodeCommit Repository**
    

* Open the AWS Management Console and navigate to the CodeCommit service
    
* Select the repository where you want to add the `index.html` file
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703665315035/cf659542-e668-4708-90e7-9c2cc6610fd7.png?auto=compress,format&format=webp align="left")

* Click on the **Create file** button
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703665349167/c847f9f8-75c0-46c6-adb5-a231dc84753c.png?auto=compress,format&format=webp align="left")

* Enter “index.html” as the file name and add the following content in the editor
    

```plaintext
<html>
  <head>
    <title>My Website</title>
  </head>
  <body>
    <h1>Welcome to my website</h1>
    <p>This is a simple website hosted on AWS CodeCommit.</p>
  </body>
</html>
```

* Click on the **Commit changes** button to save the changes
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703665757147/f8b1d568-a91f-479a-b79a-0c44978826ba.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703665818360/7c89662b-04ae-48f3-aed1-8e404e4a3c72.png?auto=compress,format&format=webp align="left")

* Clone the repository to your instance and verify the files
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703666191925/2c1a13d8-2e0b-4795-a8da-ede80d34302a.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703666467756/1f30a1b5-1614-4523-8a07-910c9fbedb35.png?auto=compress,format&format=webp align="left")

1. ### **You have to build the index.html using nginx server**
    

```plaintext
version: 0.2

phases:
  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/
  post_build:
    commands:
      - echo Configuring NGINX
artifacts:
  files:
    - /var/www/html/Index.html
```

Here’s what each step of the build does:

* version: 0.2 specifies the version of the Buildspec syntax we’re using.
    
* phases contains the build phases for our project.
    
* install: Installs nginx on the build environment using the apt-get package manager.
    
* build: Copies the index.html file to the default web root directory for nginx.
    
* post\_build: Performs any additional configuration for nginx, if necessary.
    
* artifacts: Specifies the location of the index.html file to be included in the build artifact.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703667650778/6a8fe4f3-627e-4a65-a038-2ad836e17c52.png?auto=compress,format&format=webp align="left")

* Commit the changes to the repository using the git add and git commit
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703667853054/28960214-2d18-45d0-9dfa-bc2e06d0fd83.png?auto=compress,format&format=webp align="left")

* Push the local changes to repository
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703668445678/93f808ea-f2f3-4ded-a4a3-88bf0906ed42.png?auto=compress,format&format=webp align="left")

## **🎯Task: 2**

1. ### **Add buildspec.yaml file to CodeCommit Repository and complete the build process**
    

* buildspec.yml file added to the CodeCommit repository
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703668660108/c9427da2-ab1d-434e-9381-05e99de299de.png?auto=compress,format&format=webp align="left")

* Go to the **CodeBuild** service, Click on **Build projects** button
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703668932985/79cffde6-65ee-4009-a274-a2190f7ba1e7.png?auto=compress,format&format=webp align="left")

* Click on **Create build project,** Enter project name
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703669255136/4aea20b2-0745-4a9c-bc97-8d8e7cab62cc.png?auto=compress,format&format=webp align="left")

* Go to Source section and select Repo and branch
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703669316525/4da96777-3b1e-453c-a6f0-eba1223ba8dc.png?auto=compress,format&format=webp align="left")

* Go to Environment section and enter the details as Operating system, Runtime, Image, Image version
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703669592669/5a06db25-83ce-4a61-8df7-f208e6fd39ad.png?auto=compress,format&format=webp align="left")

* Go to Buildspec section & select **Use a buildspc file** & click on **create build project**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703670310206/070b3f45-8d64-409d-a2b7-a7f037c2b994.png?auto=compress,format&format=webp align="left")

* Click on **Start build**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703670564098/c6bd2f6d-6692-4fd2-b5c5-307984e522a5.png?auto=compress,format&format=webp align="left")

* Code build is completed
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703674715594/f243131a-e08c-4c3e-8e6c-a7475a9c11be.png?auto=compress,format&format=webp align="left")

* Now go to S3 console create a bucket
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703676785606/cab80ab3-4fe6-4a6c-9a14-bade9df2b841.png?auto=compress,format&format=webp align="left")

* Bucket is created
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703676934170/4f8337a4-2ee5-42f9-8aa0-d39aa8d64f05.png?auto=compress,format&format=webp align="left")

* Go to code build and click on edit--&gt;Artifacts
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703677069983/d03ec7d5-3d68-463f-b423-46d940c7f96e.png?auto=compress,format&format=webp align="left")

* Select type of Artifacts, enter bucket name, give the name of the folder or compressed file in the bucket that will contain your output artifacts, & give the path of that folder.
    
* click on **Update artifacts**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703677631063/0660836a-961a-45e0-9942-1cd8f71562d5.png?auto=compress,format&format=webp align="left")

* Now go to build project and click on start build
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703677949796/4c3c4d3d-8ea4-4b49-b49a-546fedec9187.png?auto=compress,format&format=webp align="left")

* Go to S3 bucket & go to Index.html file
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703678086731/55e9a22a-304d-48ed-83b4-3b05e9469b86.png?auto=compress,format&format=webp align="left")

* Click on Open
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703678212596/0258a9a5-3fb8-40ea-9648-15302e662a93.png?auto=compress,format&format=webp align="left")
