# Pipeline form Code Commit repository

Pre-requisites

* AWS account
    
* Code Commit repository
    
* Local machine setup
    

In this pipeline we setup source stage and deploy stage

First, log in to the AWS Console, open the code commit repository and create a repository name: MyDemoRepository

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712150404838/0e62374f-42b4-4e08-936a-ae27cc44e9fc.png align="center")

Next you need to clone the repository to your local machine make sure git installed in the local machine

Now if you using a Windows machine go to your bash emulator like **<mark>Git Bash</mark>**

From the emulator, run the ssh-keygen command and save the file to the .ssh directory

```bash
$ ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/drive/Users/user-name/.ssh/id_rsa): Type a file name here, for example /c/Users/user-name/.ssh/codecommit_rsa

Enter passphrase (empty for no passphrase): <Type a passphrase, and then press Enter>
Enter same passphrase again: <Type the passphrase again, and then press Enter>

Your identification has been saved in drive/Users/user-name/.ssh/codecommit_rsa.
Your public key has been saved in drive/Users/user-name/.ssh/codecommit_rsa.pub.
The key fingerprint is:
45:63:d5:99:0e:99:73:50:5e:d4:b3:2d:86:4a:2c:14 user-name@client-name
The key's randomart image is:
+--[ RSA 2048]----+
|        E.+.o*.++|
|        .o .=.=o.|
|       . ..  *. +|
|        ..o . +..|
|        So . . . |
|          .      |
|                 |
|                 |
|                 |
+-----------------+
```

The above code generates a file with a private key file and public key file

Now copy the content in the public key that was generated and paste in the SSH public keys for AWS Code Commit from Security Credentials now that we have

SSH key ID

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712156334869/ff3d5678-52e4-475a-a98d-f2c742a1e88e.png align="center")

Now in git bash create a config file in the directory

```bash
vi ~/.ssh/config
```

now add the following to the config file

```bash
Host git-codecommit.*.amazonaws.com
  User APKAEIBAERJR2EXAMPLE
  IdentityFile ~/.ssh/codecommit_rsa
```

the above is SSH configuration for accessing AWS Code Commit repositories using GIT

Run the following command to connect the local machine to AWS Code Commit

```bash
git clone ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/MyDemoRepo
```

if it is successful, you will be connected to the repository

if not you need to troubleshoot the following command

```bash
ssh -v git-codecommit.us-east-2.amazonaws.com
```

---

Now add your code to the repository, i add it from the local machine

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712156942063/72d36abb-51a7-404d-a4f7-053e8e44994c.png align="center")

Push the files to the code commit

command to stage all of your files at once

```bash
git add -A
```

command to commit the files with a commit message

```bash
git commit -m "Add sample application files"
```

Run the following command to push the files from your local repo to Code Commit repository

```bash
git push
```

The files you added to your local repo have now been added to the `main` branch in your Code Commit `MyDemoRepo` repository and are ready to be included in a pipeline

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712164960187/08898d0b-e322-4096-806f-febfeb7dfa80.png align="center")

---

Create an Amazon EC2 Linux instance and install the Code Deploy agent to run your pipeline

Now we need to create roles to deploy applications

From the IAM role create a role with the name EC2Role and attach the following policies

`AmazonEC2RoleforAWSCodeDeploy`

`AmazonSSMManagedInstanceCore`

Create an EC2 Linux machine with t2.micro and at the network choose HTTP to add to EC2 security group

Create an application in Code Deploy, an application is a resource that contains the software applications you want to deploy.

* Go to Code deploy console create application and enter the name
    
* compute platform is on EC2/On-premises.
    
* Create deployment group : it defines deployment-related settings
    

---

### Pipeline in Code Pipeline

* Name the Pipeline you creating
    
* At the source stage choose Code Commit, Branch name is the main
    
* Deploy stage choose Code Deploy
    
* Add the application you created
    
* Deployment Group choose the group you created
    
* Create pipeline
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712171599807/340c844c-f99c-4b0e-93a7-6afff26d0027.png align="center")

### Validation of Pipeline

go to your EC2 machine and copy Public DNS in details Description tab and paste in the browser you see your application running

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712171788660/c6ed5602-45d3-4219-801d-f6b6f08827c7.png align="center")

Your Pipeline is configured to run whenever code changes are made to your Code Commit repository.
