Create Backend Image for HA-3-tier-E-Commerce web Application

 

Here we are creating a Backend image to be used in the Launch Template while creating a Highly Available, Fault-tolerant, 3 tier E-Commerce web Application Deployment in AWS

 

Create Backend Image for HA-3-tier-E-Commerce web Application

 

Overview of the Steps:

Step 1: Create an AWS Linux machine using AWS Linux AMI

Step 2: Install GIT, NPM, NVM, PM2, Angular and MySQL

Step 3: Download Code and install node modules

Step 4: Import the database and update it

Step 5: Changes related to running the application in the Production environment.

Step 6: Start the Application’s backend

Step 7: Check the application in the web-browser and create AWS Image

 

 

Step 1: Create an AWS Linux machine using AWS Linux AMI, using instance type t2.small ( 1 CPU and 2 GB memory) or some higher configuration machine.

Note : While creating an instance for the image creation process, we can use VPC which we have created, any public subnet and frontend security group.

 

 

Step 2: Installation

  • Install GIT: yum install git
  • Install NPM: yum install npm
  • Install Node Version Manager: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  • run command:   source ~/.bashrc
  • Install Node version 16 and use it :

nvm install 16

nvm use 16

  • Install Angular: npm install -g @angular/cli@14
  • Install PM2 : npm install -g pm2

 

  • Install and configure MySQL:

sudo yum update -y
sudo rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
sudo yum install mysql-community-server

 

Step 3: Download Code and install node modules

  • cd /home
  • mkdir webapp
  • cd webapp
  • git clone https://github.com/devopsenlight/web-app-deployment-on-cloud.git

 

  • Install node modules for backend.

cd /home/webapp/web-app-deployment-on-cloud/backend

npm install

 

 

Step 4: Import the database in the db server.

  • Grab the DB server endpoint URL from AWS, as created in this step, then perform the below step. 

– mysql -h webapp-ecomm.c1qsmoe48wu0.us-west-2.rds.amazonaws.com -u admin –p

(Enter MySQL password set while create database in AWS – RDS)

SHOW DATABASES;

CREATE DATABASE webapp;

SHOW DATABASES;   (to check if webapp database has created or not)

EXIT;

 

– Then cd to specified location and Enter the below command to upload sql_dump.sql :

cd /home/webapp/web-app-deployment-on-cloud/backend

mysql -h db-server-endpoint-url -u root -p webapp < sql_dump.sql

 

 

Step 5: Changes related to running the application in the Production environment.

  • Create a folder called env in the root of the backend directory and create a produciton.env file.

cd /home/webapp/web-app-deployment-on-cloud/backend/env

[root@ip-172-31-80-191 env]# cat production.env

PORT=80
DB_HOST='db-server-endpoint-url'
DB_USER='root'
DB_PASSWORD='********'
DB_NAME='webapp'

 

Here :

PORT=80
DB_HOST=’db-server-endpoint-url’ (enter endpoint url of DB)
DB_USER=’root’  (It will be admin , if you have setup “admin” while creating database)
DB_PASSWORD=’********’ (enter password which set up while creating database)
DB_NAME=’webapp’

 

Step 6: Start the Application backend using pm2

 

  • Start Backend

cd /home/webapp/web-app-deployment-on-cloud/backend

pm2 start npm -- start

to enable PM2 startup at restart run below command :

 

pm2 startup
systemctl enable pm2-root
pm2 save

 

Step 7: Check the application in the web-browser and create Image

ec2-35-175-245-177.compute-1.amazonaws.com (Use your own Amazon ec2 Public IPv4 DNS name)

That’s all – the backend is up and running and connected to db server.

Then create an AWS image from the AWS console – EC2 section.

 

 

That’s all, it’s done.

 

Please write your comments/queries below “or” Contact-Us

 

Please write your comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *