Project name: Deploy a multi-timer web app using SQS
Skills: AWS, Azure
Scenario: A B2B web application deployed in Azure platform has been observing decreased number of leads/enquires being generated on their website. Upon investigating the logs generated in Azure Monitor service, they found that the app servers (backend) are going down for few minutes on a daily basis. Since they are on a tight budget, they are looking for a solution which can help them in retaining the forms filled via the front-end so that even if the backend servers are down the forms data submitted by the end users are not lost. They want to apply this solution part on AWS to retain the high availability of their app.
Create an architecture and the step-by-step guide to provide a solution for the above problem statement.
Objective: To set up decoupling of a multi-timer web application deployed on Azure platform using the SQS service offered by AWS
The scenario involves deploying a B2B web application in Azure, where the backend servers frequently go down, leading to a potential loss of form data submitted by end users. The goal is to create an architecture that ensures form data is retained, even when the backend is temporarily down, by using AWS services.
Diagram
Step
Step 1: Setup frontend VM (+Vnet)
Step 2: Setup backend VM (+Vnet)
Step 3: Create AWS SQS
Step4: Create RDS (mySQL)
- Add MySQL to inbound rules
Step 5: Configure connection by CLI
-log in to frontend and backend VM
-ssh azureadmin@public ip address
1. To install MySQL CLI use this command in cloudshell:
- sudo apt-get update && sudo apt-get install mysql-client
2. Use this below code to connect between mysql server:
- mysql -u admin -p -h amanpdb.c297f9nhmqb5.ap-south-1.rds.amazonaws.com --port=3306
3. Run the following query to create DB:- CREATE DATABASE customerdb;
USE customerdb;
CREATE TABLE customers (
name VARCHAR(30) NOT NULL,
address VARCHAR(30) NOT NULL
);

****************************************************************************************************************************
Python Scripts to set up VMs as backend and frontend:
For frontend & backend:-
1. sudo apt-get update
2. sudo apt-get install awscli
3. sudo su
3. aws configure
***************
For frontend:-
1. sudo su
2. apt-get update
3. apt-get install -y python3
4. apt install python3-pip
5. pip install boto3
6. sudo nano send_message.py
7. Paste the code and change the queue URL of your VMs:
/////
import sys
import boto3
sqs = boto3.client('sqs')
queue_url = 'https://sqs.ap-south-1.amazonaws.com/001232840143/simplequeue'
response = sqs.send_message(
QueueUrl=queue_url,
MessageBody=(sys.argv[1])
)
print(response['MessageId'])
/////
8. python3 send_message.py Peter,USA send 3 more messages
For backend:-
1. sudo su
2. apt-get update
3. apt-get install -y python3
4. apt install python3-pip
5. pip install boto3
1. pip install mysql-connector-python
2. sudo nano get_message.py
4. Paste the below code:
/////
import time
import boto3
import mysql.connector
queue_url = 'https://sqs.ap-south-1.amazonaws.com/001232840143/simplequeue'
#Specify the database details
host = 'amanpdb.c297f9nhmqb5.ap-south-1.rds.amazonaws.com'
user = 'admin'
password = 'simplilearn'
database = 'customerdb'
#Create a SQS Client
sqs = boto3.client('sqs')
#Connect to the RDS MySQL Instance
mydb = mysql.connector.connect(host=host, user=user, password=password, database=database)
mycursor = mydb.cursor()
# Receive message from SQS queue
response = sqs.receive_message(QueueUrl=queue_url)
message = response['Messages'][0]
# Delete received message from queue
receipt_handle = message['ReceiptHandle']
sqs.delete_message(
QueueUrl=queue_url,
ReceiptHandle=receipt_handle
)
print('Received and deleted message: %s' % message["Body"])
#Get the customer name and address from the message
customerDetails = message["Body"]
customerDetailsList = customerDetails.split(',')
name = customerDetailsList[0]
address = customerDetailsList[1]
#Write the record to the database
val = (name, address)
sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"
mycursor.execute(sql, val)
mydb.commit()
print("Record inserted in the DB")
////
5. Enter the default region as ap-south-1
6. In the backend use the command as sudo nano get_message.py
7. Type in python3 get_message.py to run the script, Send three more messages

No comments:
Post a Comment