React CI/CD Deployment with AWS Code Pipeline on Centos7


As a someone who works in the software industry, you should always expect sudden requests from your customers to make changes on their running projects, though these changes might be minor changes, but a complete deployment process is required, which will take some time ,and tedious if repeated frequently.
Hence the need to use CI/CD pipelines has appeared, especially for companies work on big software projects.

Here is Mohamed Alomar from GeekFeed, I will walk you through a fairly Uncomplicated tutorial to  deploy  React code maintained in a CodeCommit repository to a Centos7 EC2 instance using AWS code pipeline and Apache server.

Before we begin this blog

Before we begin, you should have an activated AWS account if you do not please follow this link Create and activate AWS account

what is code Pipeline?

Code Pipeline is the glue that ties the next developer tools together so to be able to create a complete pipeline  you need  to go through these steps:

Source –  in this step the place  where your code will reside will be determined.

Artifacts – Code Artifact

Build – in this step the build process will be  performed.

Deploy – in the step the source code will be deployed  to Ec2 instance

judging from the previous definition we need to create a place in which the source code will be  placed

Create a CodeCommit repository

As mentioned  before codeCommit repository is the place  where your Pipeline will get the source code from.

steps to create CodeCommit repository

1-Open  CodeCommit console.

2-Choose AWS region where you want your repository to be.

3-choose repository name.

4-click on create button

set up a local repository

in this step you need to create local repository and connect the local repository with AWS codeCommit repository, to do that follow these steps:

1- choose Clone URL on the top right of the page, and then choose Clone SSH.

2-using your own  terminal or command line, navigate to the local repository and  execute the following command:

replace ssh_ifno by the repository address, that you have just created


Add   your code to CodeCommit repository

After creating  codeCommit repository, now  it is the time to push your code into it.

to transfer files from local repository to remote repository:

1-navigate the the local repository directory.

2-run the following commands



Regarding the highlighted files  in yellow, it will be used in the deployment stage and  in the build stage, these files will be executed each time  you  make any changes on CodeCommit repository.




Scripts files:

install dependencies:






Create an Ec2 instance and install the CodeDeploy agent

In this step you will create  Ec2 instance with Centos7 operating system, it will be used to host the source code  with the help of Apache server.

Before launching an instance:

1-Open IAM console

2-Create a role  with policy AmazonEC2RoleforAWSCodeDeploy

this role will be used  in next steps when creating  Ec2 instance, to allow Ec2 instance to use AWS CodeDeploy agent.

To launch an instance

  1. Open the Amazon EC2 console 
  2. Choose Create new  instance and  choose Centos as operating system.
  3. In IAM Role choose the previously created IAM Role
  4. In user Data add the following:

the previous code is  important to install apache server, to determine the region of the instance, and to install code deploy agent.


5.After configure the storage of the instance  Proceed without a key pair. and click  Review and launch .

Create an application in CodeDeploy

Before creating CodeDeploy application you need  to create a role that allows CodeDeploy application to

  1. In IAM console, choose Roles, and then choose Create role.
  2. After navigating to IAM Role console, choose AWS service, and from the list which will appear, choose CodeDeploy.
  3. Choose CodeDeploy – ECS. because in our case we will deploy the code  using Amazon ECS deployments.
  4. Click next and  leave  the permissions as they are.
  5. enter name to click create.


steps to create CodeDeploy application

  1. Navigate to AWS CodeDeploy  console.
  2. Choose Create application with type Custom application.
  3. Add application name.
  4. In compute platform choose Ec2/on premises.
  5. Create application.
  6. Create deployment group.
  7. In Service role, choose the name of your CodeDeploy service role that you previously  created.
  8.  Choose In-place as deployment type.
  9. In Environment configuration, add the name of Ec2 instance that you want to deploy your code to it.
  10.  Choose CodeDeployDefault.AllatOnce in Deployment configuration.
  11. In Load Balancer, clear Enable load balancing.
  12. Choose Create deployment group.

Create your  pipeline in CodePipeline

In this step  we will use the previously created components to form the complete pipeline




Verify if  your pipeline runs successfully

By accessing  the  Ec2 instance  public IP on port 80 we will be able to see the home page of our application

いいね ! しよう

Twitter で
The following two tabs change content below.
株式会社ギークフィードのサイト編集担当者です。 弊社へのお問い合わせ・質問は、お問い合わせページからお願いいたします。