Thursday, April 24, 2025

Monolithic Web Application

Monolithic web project AWS

Class 11th Worked on Monolithic Web-application

Requirement: Create a simple monolithic web application using python further i will converted it into 3 tier architecture

Require Sign-up and Sign-in pages and signup page  (Name,Mobilenumber,password and user image should be taken,data will be stored in my sql database image should be stored in the same root folder.

Tech stack:

Backend: Python(Flask for simplicity)

Frontend: HTML/CSS(basic forms)

Database: Mysql

Image storage: Stored in the root static/images/ folder of the project 

Step1:Create one Windows VM


Step2:After Launch completed ,need attached security key using below navigation
Step3:Upload private key pair which you downloaded and then click Decrypt Password,it will generate the password connect VM ware
Step4:Below password generated ,this auto generated Privatekey and public key combination generate password

Step5:Follow below chatgpt 
https://chatgpt.com/share/680a6197-31c0-8008-bd19-b051a105a25b
Step6: Search Google test Python install window click below url while download No thank just download 
Installation steps:
While installation choose Full (Workbench is required that is database editor)
After Click Next, Next
Given Password Root password 
Click Next, Next 
Click Execute
Click Finish and Cancelled 

Step7:Go window enter Mysql work beach ,it uses for query sql editor table access
After installation remove default instance connection which there
select and Delete existing root connection select delete connection, Need to give connection manually 

Given your root/password connection test connection and then click ok
Step8:Above icon Create schema click apply, apply Finish
Step9: Select schema tab below ,create tables

Step10: Need to create below Folders in  VM C:\
OnlineLibrary/
├── app.py                         # Main Flask application
├── config.py                      # DB config and connection settings
├── requirements.txt               # Python dependencies
├── templates/                     # HTML templates
│   ├── signup.html
│   ├── signin.html
│   └── welcome.html
├── static/                        # Static files (CSS, images, JS)
│   ├── css/
│   │   └── style.css              # Your custom styling
│   └── images/                    # Uploaded user images

 Change below Config file

Step11:Python need to install ,Google text search Python install window 11
  
Step12:
requirements.txt
Flask
Flask-MySQLdb
Werkzeug
Step13:After completion required flash installation, need execute final step phyton script run 
We can copy the files or file text to your files using below url
https://drive.google.com/drive/folders/1UU3FBE2QjRdsb9KuvNfigkm6JAVKSzBa?usp=drive_link

Step14:After execute below, click url ctl or else copy the url past to the browser 

Step15:Login page came successfully

Step16:Click signup Give your details and click signup,

Step17:Afer you signup, get message Registration successful please login and check once 
you need check in database data inserted or not ,you see below records inserted


 Step18: Login once with your credentials 

Our Project Gobal accessing 

Step1: Need to execute some commands in the project folder 
python -m venv venv 
venv\Scripts\activate
pip install waitress


Step2:Allow Access in Firewall  Open Windows Defender Firewall ➜ Inbound Rules ➜ Add a New Rule :Type: Port,Port: 5000,Allow connection,Apply to Domain, Private, Public 
Name: Flask Web App (Name as you wish) , I have given 5000 ip


Step3: After port added in the firewall ,execute the python app.py  command again ,now it is  start started

Step4:Now Access your application Globally with our public ip and port number ,while you create VM Public IP accessed for that ,take that ip entension with port number 

You see below sign in page successfully
 
Step5:After login with old user ,login successfully
Step6:Now you signup new user ,with details click signup
 

Step7:Registered successfully getting screen below

Step8:Check once Mysql table level data stored or not for new user 
  
You see above new regarding inserted successfully, this is the way Monolithic Simple project build

Monolithic Architecture: Everything Frontend (UI) ,Back-end(logic),Database Access  is combined into one big application called monolithic.

We have Three Layer of approach
 1.Presentation Layer ->Frontend(HTML/CSS/Javascript)
 2.Application Layer ->Backend (Python Flask APIs)
 3.Data Layer ->Database (Mysql) 


                          --Thanks






Wednesday, April 23, 2025

Ec2 part2

Ec2 part2

 Class 10th Elastic compute cloud Apr 23rd

  • Load Balancer 
  • Target groups
  • Launch Templates 
  • Auto scaling

Step1: VPC Created
Created One VPC  with CIDR block 10.0.0.0/22 that means 32-22=10  ,Power(2,10)=1024 Subnet Ips we can able create


Step2:We have created 6 subnets 3 for public and 3 for private for above VPC, with different available zones.

Step3:Create two route table private/public subnet attached to associate subnets




Step4:Click  all your public and private subnet edit subnet check enable auto-assign public and save
Step5: Need to create one internet gateway and attached our VPC


Step6:
What is the ELB?
Elastic load balancing automatically distributes incoming application traffic access multiple targets,such as amazon instances,container, IP addresses,lambda functions and virtual appliances.

https://google.com search(user)-->Webserver-->database 
Web server has capacity limited(if request came more than capacity system will crash,so the reason implemented load balancer
user -->loadbalacer->Webserver -->Webserver -->database
                                     
the load balancer equal to distributed multiple webserver instances

Elastic Load balancing types 
1.Application load balancer (commonly used ,round robin method distribute)
2.Network load balancer 
3.Gateway load balancer 
4.Classic load balancer (old one)

Target groups :we have registered instance to the target group which is you have created
Target groups route requests to one or more registered targets, such as ec2 instances, using the protocol and port number that you specify.
You can register a target with multiple target groups. You can configure health checks on  a per targetgroup basis.
Health checks are performed on all registered to a target group that is specified in a listener rule for your load balancer

Practical
Step7: Need to attach internet gateway to private /public Route table also.


Step8:We have to three instance created,




Step9: Advance details and scrip user data Apache data  and click launch
#!/bin/bash -xe

# STEP1 -Updates
yum -y update

# STEP2 -Begin Configuration
yum -y install httpd
systemctl enable httpd
systemctl start httpd

# STEP3 -Customer Web Page
echo "<h1> Welcome to Website1</h1>" >> /var/www/html/index.html


Step10: Three instances created with three different zone due high availability 
VM_Inst_website1,VM_Inst_website2,VM_Inst_website3 and modify iam security attach admin for all 3 VM's

Step11:



Step12:Need to Create Target group and attached 


Our three instance check all click include as pending as below
and click create target group

After registered Target group inital it will consequently health check ,while health 200 success code need get response, if not our instance is not healthy
Every 30 seconds target do the health for the instance if any issue on instance that server went to
 unhealth state


Create Load balancer  Application Load Balancer 
Step1:

          
select default security group and ,select out Target group

Click load balancer

     

Step2: Take the DNS name CCIT-LBCER-137143466.eu-west-1.elb.amazonaws.com load balancer test,
as you see below same website url connected ,different sites, this way load balancer will work


Step3: Just for test stop the one instance and then need to target group available zone


Step4:As you see below one avaaille zone went unsed state 
Step5:Even though our website available to two zone


                                                                           Autoscaling
(whenevery one instance was down, autscaling automatically create on instance and attach to target gropd)
Autoscaling is monitoring your applications automatically adjust the capacity to maintain steady, predicatable performance at the lowest possible cost.
Using AWS auto scaling, it's easy to setup application scaling for multiple resources across multiple service in minutes 
It's easy to get stared with auto scaling using the AWS management console,command line interface (CLI), or SDK 
AWS Auto scaling is available at no additional charge .You pay only of the AWS resources needed to run your applications and amazon cloud watch monitoring fees.

Type of Scaling 
  • Vertical Scaling  
  •  Horizontal Scaling 
Vertical scaling means increasing the capacity of the existing resource .Increasing RAM capacity, adding additional volumes, change  the instance family under this category 
Note: Vertical scaling need change capacity for instance need downtime/stop instance

Horizontal 
(For Particular time you want required instance capacity need to increase with out downtime ,we implement Horizontal downtime)
Horizontal scaling means adding additional nodes or machines to your infrastructure as per demand. 
we can setup automation to this scaling.

Launch Template 
Create Template  choose the instance type t2.micro free tier 

Additional details,pls User data give below information 

#!/bin/bash -xe

# STEP1 -Updates
yum -y update

# STEP2 -Begin Configuration
yum -y install httpd
systemctl enable httpd
systemctl start httpd

# STEP3 -Customer Web Page
echo "<h1> Welcome to Blog</h1>" >> /var/www/html/index.html

 
Not to change anything click Create lunch template

Step6: Need to configure auto scaling group need attach the launch template which is we have created
autoscaling create the instance based which specified on the launch template
Click Next


Choose your VPC and select all private subnet click next 

Attach your existing loadbalancer 

click Next 

Enter how many instances you need 

Give 3 click next >add notification >click next -->add tag >click next 

Step7:

Click create autoscaling group

Once create Autoscaling group ,Three instance automatically created 

As you above it was created three availability zones, we have specified launch template 
and autoscaling show three availability zones
As you see using public IP , all http pages are opened 



All Instance we have put private, we have put only loadbalacer public 

As see Target groups are health state.


Test Auto scaling now, terminate one instance manually , need check is will automatically create instance or not using autoscaling 

Terminate one instance 

 Terminated done 


You see automatically one more instance created by autoscaling ,After 300 seconds


 You see our webpage all also automatically came ,autoscaling created instance with same configuration and out webpage
Below out autoscaling min once created max 3 instance automatically




Autoscaling ,We can Instance CPU utalinzation also based on target value 50 % more, it will create
new instance automatically and distributed the load balance 


Deletion
Terminate the instance 
delete autoscaling 
delete loadbalance
delete targetgroups


                     --Thanks