Presentation layer ➡️ handles user interactionApplication layer(backend logic) ➡️ processes business logic and data processingData layer (database) ➡️ manages data storage and retrieval
Your VPC's button on the left and then click on Create VPC the button on the top right corner of the page
172.20.0.0/16.
subnet button which is located on the left side and then click on theCreate subnetbutton on the top right corner of the page.

Create subnet button.

internet gateways button at the left panel. and then click on the Create Internet gateways button on the top right corner of the page.


Attach Internet gateway button.
NAT gateways button on the left panel of the web page. and then click on the Create NAT gateways button in the top right corner of the page.
Allocate Elastic IP button to allocate Elastic IP. and then click on the Create NAT gateways button. NAT gateways creation takes 2-4 minutes.

create route table.

Routes tab at the bottom and then click on the edit route button.
Add Route button. and select 0.0.0.0/0 in the destination field. and then click on the Target field. As soon as you click on the Target field one drop-down will open and here you have to select Internet gateway, shown in the below image.
save changes button.
Subnet associations tab next to the Routes tab. and then click on the Edit subnet associations. as shown in the below image.
save associations button.

0.0.0.0/0 in the destination field and click on the target. As soon as you click on the target you will see the drop-down list. Please select NAT gateway from the drop-down list. As shown in the below image.
save changes button.
subnet associations tab at the bottom next to the Routes tab. And then click on the Edit route associations button.
save association button.
action button and there you will see the drop-down menu. Select the Edit VPC setting button. As shown in the image.
Save button
action button and then choose the Edit subnet setting button from the drop-down list.save button

Security Groups button. Note that SGs are specific with VPC. So we can’t use SG which is created in a different VPC. So when you create SG please make sure that you choose the right VPC. click on the crate security button on the top right corner.
Add rule button in inbound rules. And add SSH rule and add your IP in the destination. Please don’t do anything with the outbound rule if you don't have a good understanding. And then click on the create security group button.






subnet group button on the left panel. And click on the button Create database subnet group which is in the middle of the web page.
create button.

database button on the left panel and then click on the created database button.
stander create because I’m going to show you each and every step. select MySQL in the engine option because our application runs on MySQL database. If your app runs on other engines you can select that one. Furthermore, you can select the engine version my application is compatible with MySQL version. But you can select according to the developer guild.
Dev/test as template. If you select the free tier then you won’t be able to deploy RDS in a multi-availability zone. Select Multi-AZ DB instance from availability and durability option. In settings give any name to your database. In the credential setting give the username of the database in the Master username field and give the password in the Master password field. And then confirm the password below. Please do remember your username and password.
Brustable class in the instance setting and select the instance type. Actually, it depends on your application uses. But for learning purposes, I am selecting t3.micro. now in storage type select General purpose(GP2) and allocate 22 GiB for database. Please uncheck the auto-scaling option to keep our costs low. And In the connectivity option please select the option according below screenshot.No, choose existing security, and select security group book-rds-db.test because we need a database with the name of the test in the application. Enable Automated Backup. Note: you have to enable automated backup otherwise you won’t be able to create a read replica of the RDS instance.Create database button below.Available then select the database and click on the Action button. There you can see the drop-down list. Please click on created read-replica.Oregon (us-west-2). Give a name to your read replica, and select all the necessary configurations that we did before while creating the database. For your reference, I have shown everything in the below images.create replica . It will start creating that.Create hosted zone.create record button on the top right corner.simple routing,defined record button in the middle of the box.book in the record name field. In the record type select CNAME. In the value field paste endpoint of the RDS which is in us-east-1. Then click on the defined record button.create record button.ankitjodhani.club in Route 53. Now I am going to use this domain name to create subdomains such as api.ankitjodhani.club and that will resolve ALB-backend DNS. Furthermore, we need an SSL certificate so that we can make the connection secure.list certificates button on the left panel and then click on the request certificate on the top right corner.next button. *.Your_Domain_Name.xyz in my case it is *.ankitjodhani.club DON’T DO ANY TYPO. In the validation method select DNS validation and click on the request certificate.create record in route 53 and click on the create record button. That’s itissued.target group button on the bottom of the left panel. And click on the create target group button in the middle of the page. Next button.create target group button.create target group button. Select the target type Instance. Again give some meaning full name such as ALB-backend-TG. Select VPC that we have created.next button. creatd target group. That’s it.Load Balancer button at the bottom of the left panel and click on the create load balancer button. First, we will create ALB for frontend.create button.create load balancer button.Created Load balancer buttonadd listener the button that is located on the right side.HTTPS. Default Action should be Forward and select ALB-backend-TG. Now we need to select the certificate that we have created. So in the Secure Listener setting select the certificate. And click on the add button below.instance button and then click on the Launch Instance button on the top right corner.t2.micro. click on Create key pair if you don’t have it.PEM file format as I have shown in the below image. Because we are going to use Git bash to do the login NOT putty and give any name to your key. And save it somewhere safe location on your computer.Advance details option. launch instance button.#!/bin/bash
sudo apt update -y
sudo apt install apache2 -y
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs -y
sudo apt update -y
sudo npm install -g corepack -y
corepack enable
corepack prepare yarn@stable --activate --yes
sudo yarn global add pm2t2.mirco as instance type. Here we don’t have to create a new key, we can utilize the previous key that we have created while launching the frontend instance.advance details option.#!/bin/bash
sudo apt update -y
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs -y
sudo apt update -y
sudo npm install -g corepack -y
corepack enable
corepack prepare yarn@stable --activate --yes
sudo yarn global add pm2ssh -i <name_of_key>.pem ubuntu@<Public_IP_add_of_Instance>yesgit clone https://github.com/AnkitJodhani/2nd10WeeksofCloudOps.gitcd 2nd10WeeksofCloudOps/clientvim src/pages/config.jsI the button on your keyboard to edit the file. In this file, we have to change API_BASE_URL. So remove whatever is present in the API_BASE_URL variable.https://api.ankitjodhani.club, In my case I have added this URL but in your case it is different. This means you need to use your OWN domain name. so your API_BASE_URL should be like https://api.<YOUR_DOMAIN_NAME>.XYZ I hope it makes sense. After updating the variable press ESC key on your keyboard and then type :wq and hit the Enter button.API_BASE_URL = https://api.ankitjodhani.clubhttps://api.ankitjodhani.club And lastly, that will point to our backend server.npm install in the terminal to install all the required packages.npm install npm run build to create the optimize static pages.npm run buildls command0sudo cp -r build/* /var/ww/html/sudo cp -r build/* /var/www/html/var/www/html so that Apache can serve them.temp-frontend-server configuration is completed. Now let's set up the temp-backend-server. So select the temp-backend-server and copy the IP address of the instance. Again please open Git bash in the same directory where your stored key.pem file. And type the below commandssh -i name_of_your_key>.pem ubuntu@<Public_IP_add>git clone https://github.com/AnkitJodhani/2nd10WeeksofCloudOps.git2nd10WeeksofCloudOps/backend cd 2nd10WeeksofCloudOps/client.envvim .envI button on your keyboard. And copy the code given below and paste the snippet into the code editor. This code contains information about the RDS instance. Please change your username and password according to whatever you kept while creating a database. And then click on the ESC button and type :wq and hit the enter buttonnpm install
npm install dotenvsudo pm2 start index.js --name "backendApi"sudo pm2 listtemp-frontend-server and click on the Action button in the top right corner. One drop-down menu will open. You have to select the images and template option and that will give one more drop-down menu from which we need to click on create image button.create image button.temp-backend-server as well. I have shown you each and every step in the below images.AMIs button on the left panel and you can see both images here.Backup Vault button on the left panel and then click on the create backup vault button on the top right corner.create backup vault button.Backup Plan button on the left side and click on the create backup plan on the top right corner.build new plan and give a name to your backup plan. In the backup rule configuration, we can set up our backup rules. So give a name to your rule. Select the backup vault that we have created just now. And in the rest of the parameters select as I have shown you in the below image. Take note that in the backup window start time please select 10 minutes more than the current UTC time so that we can see the output of the backup quickly.destination region where you want to copy your resource. In my case, it is us-est-2 (Oregon region). And you can select the default backup vault if you don’t want to create a backup vault in Oregon just like me. And all the rest of the parameters select as I have shown you below in the image. And lastly, click on the Create plan button.include specific resource type. And from the select resource type drop-down select EC2 and choose the instance ID of temp-frontend-server and temp-backend-server. I would recommend referring below image. And then click on the Assign resource button below.Jobs button on the left panel and here you can see the backup job. It took 20 minutes to initiate the job so we have to wait.AMIs section of the EC2 service. we have a total of 4 images and 2 running servers in the N.virginia region.copy jobs tab.AMIs section Oregon region.launch template button on the left panel and click on the create launch template button.template-frontend-server as we are creating a launch template for frontend-server. let's give the version 1 in the version field. Here we need to select AMI so click on My AMIs tab and select the option owned by me. So now it will show you all the images that are present in your current region. If you are following the blog from starting then you will have a total of 4 images in N.virginia. coz two we created manually and two were created by backup service. Here you have to select the image that contains the frontend application. Either you can select the manual or the one created by the backup service. both are okay coz it contains the same data. Select instance type t2.microfrontend-sg. And click on the advance details section at the bottom of the page.Create launch template button.#!/bin/bash
sudo apt update -y
sleep 90
sudo systemctl start apache2.service
(template-backend-server). Give version 1 in the version field, but make you select the correct AMIt that holding your backend application. And Select an instance type t2.microbackend-sg. And click on the advance details section at the bottom.Create launch template button.#!/bin/bash
sudo apt update -y
sleep 150
sudo pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/local/share/.config/yarn/global/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
sudo systemctl start pm2-root
sudo systemctl enable pm2-root
two launch templates, template-frontend-server and template-backend-server in N.virginia.AMIs. Please select the correct AMI for the frontend and backend. If you have difficulties finding AMIs you can compare the instance_id with temp-frontend-server and temp-backend-server. this will definitely help you.temp-servers to save the bills.Auto scaling groups button which is located at the bottom of the left panel. And then click on the Create auto scaling group button.ASG-frontend . And select the launch template that we have created for frontend (e.g template-frontend-server ) in the launch template field. And click on the next button.pri-sub-3a and pri-sub-4b. these subnets we have created for frontend servers. And click on the next button.ALB-frontend-TG. And then scroll down and click on the NEXT button1,1,1 to save cost but in real projects, it depends on the traffic. Click on the NEXT->next->next-> and create ASG button.ASG-backend. And select the launch template that we have created for the backend (e.g template-backend-server ) in the launch template field. And click on the next button.pri-sub-5a and pri-sub-6b. these subnets we have created for backend servers. And click on the next button.Attach existing ALB option and select TG that we have created for the backend e.g ALB-backend-TG. And then scroll down and click on the NEXT button.1,1,1 to save cost but in real projects, it depends on the traffic. Click on the NEXT->next->next-> and create ASG button.ASG-frontend will launch frontend servers and ASG-backend will launch backend servers. we have successfully set up ASG in the N.virginia region and we need to do the same setup in the Oregon region as well.bastion host or jump-server. And through that instance, we will log in to the backend server, and from the backend server we will initialize our database.instance button on the left panel and click on the launch instance button in the top right corner. Please terminate those temp-servers if you haven'tbastion-jump-server). Select Ubuntu as OS, instance typet2.micro, and select Key pair. In all the instance and launch template we have used only one key so it will be easy to login in any instance. And then click on the Edit button of the Network setting. pub-sub-1a, you can select any public subnet from the VPC. and then select security group. We already have a security group with the name bastion-jump-server-sg and click on the launch instance.scp -i <name_of_your_key>.pem <name_of_your_key>.pem ubuntu@<Public_IP_add_of_instance>:/home/ubuntu/key.pemssh -i <name_of_your_key>.pem ubuntu@<Public_IP_add_of_instance>chmod 400 key.pemssh -i key.pem ubuntu@<Private_IP_add_backend_server>cd 2nd10WeeksofCloudOps/backendsudo apt install mysql-server -yAnd type the below command to initialize the database.mysql -h book.rds.com -u <user_name_of_rds> -p<password_of_rds> test < test.dbALB-frontend DNS then you won’t see the website in functional mode because our frontend or loaded static pages try to call the API from your browser on the domain namehttps://api.<Your_Domain_name>.xyz In my case, https://api.ankitjodhani.club And that record we didn’t add yet in our domain name. so let’s do that.health check button on the left panel.create health check button.HTTP and in the Domain name field give the DNS of the ALB-backend which is in US-EAST-1 because us-east-1 is our primary region. And fill in all the details as I have shown you in the below image. And then click on the next button.hosted zone and select your public hosted zone or your domain. I already have one. And click on the Create record button in the top right corner.failover record. And click on the next button.api so that our record name becomes api.<Your_Domain_name>.xyz in my case, it is api.ankitjodhani.club . in the record type field select “A” and then click on the define failover record button.Alias to application and classic Load balancer from the drop-down list, secondly, select us-east-1 as a region. And in the below drop-down list select DNS of the ALB-backend. As you know that us-east-1 is our primary region so select primary in failover type. And in the health check ID select the health check that we have created just now. And click on the Define failover record button. Follow the below image for more clarity.create record button. failover record with the same domain name but for a secondary region. Firstly Select Alias to application and classic Load balancer from the drop-down list, secondly, select us-west-2 as the region. And in the below drop-down list select the DNS of the ALB-backend. As you know that us-west-2 is our secondary region so select secondary in failover type. Make sure you don’t select anything in health check ID. And click on the Define failover record button. Follow the below image for more clarity.ALB-frontend) and paste it into the browser. I am sure that you will see the website in fully functional mode. You can add and remove books.distribution button on the left panel and then click on the create distribution button on top right corner.ALB-frontend (us-east-1 primary region). Select Match Viewer in the protocol field. And scroll down CashingDisabled and in cache policy and select AllViewr in origin request policy.add item button and add an alternative domain name (threetier.ankitjodhani.club) and select the certificate that we have created in the Custom SSL certificate field.create distribution.
distribution that we have created just now and click on the Origin tab. Here you need to select create origin the button in the top right corner.
ALB-frontend ( us-west-2 secondary region ), select math view in protocol and the rest of the parameters are all the same so click on the create origin button.
ALB-frontend which is in us-east-1 and the second one is pointing to ALB-frontend which is in the secondary region Oregon (us-west-2). Now click on the create origin group button.
us-east-1 and click on the add button. And again click on the origin field and select the origin that is associated with us-west-2 and click on the add button. Give any name to the origin group (frontend_failover_handler) and select all the failover criteria as I have shown in the below image. Hit the button created origin group.
behavior tab. And select the behavior and click on the edit button.frontend_failover_handler). Scroll down and click on the save button.
create record button.
simple record, and click on the button defined record. In the record name, add name threetier so our domain name becomes threetier.<Your_Domain_name>.XYZ, in my case, it is threetier.ankitjodhani.club. Select record type “A”. Select Alias to CloudFront distribution from the drop-down list in value/route traffic to field. And select the distribution that we have created just now. Lastly, hit the define simple record button. Route 53 takes sometime around 5-10 minutes to route traffic on the newly created record so please wait.
https://threetier.ankitjodhani.club. I am sure you can see the website in a running state.
We are almost done before we taste our application one small service but very essential service we want to utilize and that is WAF.Web ACLs on the left panel and then click the button which is in the middle Create Web ACL.Add AWS resource button and add the CloudFront distribution that we have just created.
add rule button on top and click Add manage rule group.
save it.
next button and that’s it. we secured web application. You can see Web ACLs in the list.ALB-frontend and ALB-backend. To make our frontend server and backend server inaccessible from the internet in US-EAST-1 region. So we can create a situation like a disaster.ALB-frontend-sg.
ALB-frontend-sg. Click on the edit inbound rule. And remove all the HTTP and HTTPS rules from it. after doing this our CloudFront distribution won’t be able to access this ALB-frontend and it have to route traffic to another region (us-west-2) ALB-frontend.
ALB-backend-sg.ALB-backend-sg. Click on the edit inbound rule. And remove all the HTTP and HTTPS rules from it. after doing this route 53 will find it unhealthy and it have to route traffic to another region (us-west-2) ALB-backend.


origin tab. Select the first origin and click on the edit button.additional settings tab. And decrease the number. So that CloudFront won’t wait too long for a response.

Posted Aug 12, 2023
Build Resilient Three-Tier Architecture Deploying the MERN Stack app on AWS: Achieving High Scalability, high Availability, and Fault Tolerance.