DEV Community

Revathi Joshi for AWS Community Builders

Posted on

6-part series - (6) Create a CodePipeline to see the changes that you made to the index.html file auto-populated

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

2nd article

3rd article

4th article

5th article

Let’s get started!

Please visit my GitHub Repository for CI-CD/Docker/ECS/ECR articles 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

CodeBuild

CodeDeploy

AWS CodePipeline

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

Build - AWS CodeBuild succeeded

Image description

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

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

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

  • 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

4. Test the Pipeline

  • On to the EC2 instance terminal
sudo su
cd /opt/docker/my-codecommit-repo
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Image description

  • 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

Image description

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

Top comments (0)