AWS 2-tier architecture

AWS 2-tier architecture

Deploying a 2-Tier Application on AWS EC2

1. Login to AWS

  • Access your AWS Management Console.

2. Infrastructure Setup

Provisioning an EC2 Instance:

  • Launch an EC2 instance to host your application.

    -ubuntu image

    -allow http, https and ssh access

    - remaining, default settings

  • Instance is created

3. Database Layer

Creating a DynamoDB Table:

  • Set up a DynamoDB table (in this case," Users") for storing user data.

  • Rest, default. Create Table

Configuring IAM Role for DynamoDB Access:

  • Create and attach an IAM role to your EC2 instance with DynamoDB full access.

  • Navigate to IAM SERVICES

  • - Select ROLES> CREATE ROLES

    -Select EC2 Services

  • -Select dynamodbfullaccess role

  • - Role Successfully Created

    -Assign Role to EC2 instance

    -ACTIONS >SECUIRTY > MANAGE ROLES

  • Select the role u have created.

  • 4) Application Layer

    SSH into EC2 Instance:

    • Connect to your EC2 instance using SSH.

    • Update and Upgrade Packages:

      sudo apt-get update

      sudo apt-get upgrade

    • Install Node.js:

        sudo apt install nodejs
      

      Clone the Project Repository:

        git clone <repo-url>
      

      Repo Url:-https://github.com/ahannan08/ReactPro.git

    • Navigate to Project Directory:

      • Change to the directory where the project files are located.

      • Since my project is located in root directory

    • 5)Configuration:

      • A) Backend Configuration:

      • Server Code (server.js): Handles DynamoDB interactions and defines registration/login endpoints.

          cd backend
        
          //install libraries for backend
          npm install express aws-sdk body-parser bcryptjs  
        
          //make changes to code 
          nano server.js 
          ( to make changes to vpc and table name)
          //if u named the dynamo table u created "Users" and
          //u launched ur ec2 in ap-south-1a ,
          //no need to make changes to server.js.
          //but if any one is different, u need to rectify server.js
        
        • Run Backend with PM2:

            sudo apt install pm2
            pm2 start server.js
          
            //to check for logs ( Reason why  error encountered during 
            Login or Regis in Real time )
            pm2 logs
          

          b) Frontend Configuration:

  • Code for Authentication: (Update with your AWS public dns and port in Routes in Register.js and login.js)

  • Product and Cart Functions

  • Checkout Functionality

      //come out of backend dir
      cd ../
      cd src/pages
      nano Register.js
      //make changes in the Routes . paste ur awspublic dns
      nano Login.js
      //same
    

  • //same for handleRegister

7. Configure Security Groups

-http from 80 , https from 443, ssh from 22 ( this will be created at the time of instance creation)

-custom tcp for 3000 and 5000 from anywhere (frontend and backend respectively)

6. Accessing the Application

//Go back the main folder Reactpro to install npm
npm install
npm start

Use the public DNS of your EC2 instance to access your application on port 5000 (e.g., http://ec2-public-dns:5000).