6-part series - (6) Create a CodePipeline to see the changes that you made to the index.html file auto-populated
Tags: pipeline, codecommit, codebuild, codedeploy
Published: 2023-02-18 02:10:43

In this **6-part series on configuring a CI/CD pipeline using Customized Docker image on an Apache Web Server, Application Load Balancer, ECS, ECR, CodeCommit, CodeBuild, CodeDeply services** -

In the **6th article**, We will create a CodePipeline to see the changes that you made to the index.html file autopopulated


**1st article**
- As a reference, please read my **[1st article - 6-part series - (1) Deploy a Custom Docker Image with Centos on an Apache web server and Save it to AWS ECR Repository](https://dev.to/aws-builders/6-part-series-1-deploy-a-custom-docker-image-with-centos-on-an-apache-web-server-and-save-it-to-aws-ecr-repository-186)**

**2nd article**
- As a reference, please read my **[2nd article - 6-part series - (2) Create Task Definition in ECS and Application Load balancer for the Task to be run on Fargate Cluster](https://dev.to/aws-builders/6-part-series-2-create-task-definition-in-ecs-and-application-load-balancer-for-the-task-to-be-run-on-fargate-cluster-1ohm)**

**3rd article**
- As a reference, please read my **[3rd article - 6-part series - (3) Create Fargate Cluster, and a Service which can access customized Docker image ](https://dev.to/aws-builders/6-part-series-3-create-fargate-cluster-and-a-service-which-can-access-customized-docker-image-1dl7)**

**4th article**
- As a reference, please read my **[4th article - 6-part series - (4) Create, clone a CodeCommit Repo, move-push the Dockerfile and index.html to remote repository master branch](https://dev.to/aws-builders/6-part-series-4-create-clone-a-codecommit-repo-move-push-the-dockerfile-and-indexhtml-to-remote-repository-master-branch-37ng)**

**5th article**
- As a reference, please read my **[5th article - 6-part series - (5) Create a CodeBuild Project, upload the code and push it to the master repository](https://dev.to/aws-builders/6-part-series-5-create-a-codebuild-project-upload-the-code-and-push-it-to-the-master-repository-p7i)**

_**Let’s get started!**_

Please visit my **[GitHub Repository for CI-CD/Docker/ECS/ECR articles](https://github.com/awsmine/Docker_projects)** on various topics being updated on constant basis.

# Objectives:

**1.** Create a CodePipeline

**2.** Add S3 policy to the role created by Codepipeline

**3.** Go to the CodePipeline, modify the Deploy stage

**4.** Test the Pipeline

**5.** Add, commit and push the file index.html to the remote repository’s master branch

**6.** Delete all the following services.


# Pre-requisites:
- AWS user account with admin access, not a root account.
- AWS CLI.

# Resources Used:

**[CodeCommit](https://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html)**

**[CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html)**

**[CodeDeploy](https://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html)**

**[AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html)**


# Steps for implementation to this project

## 1. Create a CodePipeline

- **`on CodePipeline under Developer Tools, Pipelines, Create pipeline, my_codepipeline, Next`**

**1.** Add Source stage

- **`Source provider : Choose AWS CodeCommit, Repository name : my-codecommit-repo, Branch name : master, default, Next`**

**2.** Add build stage

**`Build provider : Choose AWS CodeBuild, Region : Default (US East N.Virginia), Project name : Choose my_codebuild_project, default, Next`**


**3.** Add deploy stage

**`Deploy provider : Choose Amazon ECS, Cluster name : my_cluster, Service name : Choose my_service, Image definitions file : Enter imagedefinitions.json, Next`**

- Create Pipeline.

**Source - AWS CodeCommit succeeded** 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pg2pq8o9o1jkau9ycwy.png)

**Build - AWS CodeBuild succeeded**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aveyzftsi7vdl4153s36.png)

**Deploy - AWS CodeDeploy failed**

- Failed - Due to insufficient permissions as the created role does not have S3 permissions
- Add S3 policy to the role created by Codepipeline.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83kixbz652bxa7wzqv3v.png)


## 2. Add S3 policy to the role created by Codepipeline

- **`On the IAM console, Roles, search and click for the role starting with AWSCodePipelineServiceRole-us-east-1-my-codepipeline which was created with the codepipeline, On the Permissions tab, Add permissions, Attach policies, Search and select AmazonS3FullAccess, Attach policies`**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bticldf0a5pm09x0vkgn.png)


## 3. Go to the CodePipeline, modify the Deploy stage

- **`my-codepipeline, Edit in the Pipeline, edit the Deploy stage`**

- Click on the Edit symbol.

    
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u93xjoztn4p4fllb4ejr.png)


- **`In the Input artifacts, choose SourceArtifact, Done, Save and Save, Now click on Release change, Release`**

**you can see that the pipeline restarts execution and it works now**



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dcs0wbx76fmfdujj3es.png)


## 4. Test the Pipeline

- **`On to the EC2 instance terminal`**

```
sudo su
cd /opt/docker/my-codecommit-repo
```


**the index.html file**

- vi index.html, add the following code, save the file

```
<!doctype html>
<html>
  <head>
    <title>Codepipeline Project</title>
  </head>
  <body>
    <h1>This is my Codepipeline with ECR, ECS, CodeCommit, CodeBuild and CodePipeline! </h1>
  </body>
</html>
```



## 5. Add, commit and push the file index.html to the remote repository’s master branch


```
git add .

git status

git commit -m "changing index.html File"

git push
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h11zeixk2k7g7yieb639.png)


- Wait for 4-5 minutes till all the execution stages are Successful.

- Now, copy the load balancer DNS and paste it in a browser tab to check the changes done you made in the index.html file.

**We have successfully deployed the CI/CD Pipeline for ECR, ECS, CodeCommit and CodeBuild**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7x5bh1f3h7ovd5g6zldi.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wxracb9g6lagyp7ipdi.png)


## 6. Delete all the following services

- EC2 Instance

- Application Load Balancer

- Target Groups

- ECR Repository

- ECS Cluster

- ECS Task Definitions

- CodeCommit Repository - Desired tasks to 0

- CodeBuild Project

- CodePipeline

- S3 Bucket

# What we have done so far

- We have successfully deployed the CI/CD Pipeline for ECR, ECS, CodeCommit and CodeBuild