Class 65th AWS Project day 4 July 11th
Final day for AWS Complete Project
Step1: This Git code upload all lambda function and main app.py file
https://github.com/Vakatisubbu/Lambda_prj.git
Step2: Create launch template ,base on the autoscaling and target group creation steps
Name: Launch-template
AMI:Amazon Linux (Free tier eligible)
Instance Type: t2.micro(Free tier eligible), Network setting Don't include in launch template
we will do at time of autoscaling
Step4: click Advance detail , add below code user data
#!/bin/bash # Update system and install dependencies yum update -y yum install -y python3 python3-pip git # Configure Python environment python3 -m pip install --upgrade pip python3 -m pip install --user flask requests boto3 # Clone the project cd /home/ec2-user git clone https://github.com/Vakatisubbu/Lambda_prj.git # Set proper permissions (added your requested lines) sudo chown -R ec2-user:ec2-user /home/ec2-user/Lambda_prj/ sudo chmod 755 /home/ec2-user/Lambda_prj/ cd Lambda_prj # Create systemd service file cat << 'EOF' > /etc/systemd/system/digital_library.service [Unit] Description=DigitalLibrary Flask App After=network.target [Service] User=ec2-user Group=ec2-user WorkingDirectory=/home/ec2-user/Lambda_prj ExecStart=/usr/bin/python3 app.py Restart=on-failure RestartSec=5s Environment="PATH=/usr/local/bin:/usr/bin:/bin" # Security hardening NoNewPrivileges=true PrivateTmp=true ProtectSystem=full [Install] WantedBy=multi-user.target EOF # Enable and start the service systemctl daemon-reload systemctl enable digital_library systemctl start digital_library
Step5: Then click create launch template,created launch template
Step6:select the template and actions>create autoscaling groupStep8:Attached new load balancer
Step9:Public subnets new name give to target group Target-group
Step10:No changes,click Next
Add notification -optional Click next
Add tags -option Click next
Review >Create Autoscaling Group
Note: Subnet Public ip must automatic enabled
Step14:Create new service Demon service
First Sever
[ec2-user@ip-10-0-2-60 systemd]$ cd /etc/systemd
[ec2-user@ip-10-0-2-60 systemd]$ sudo vi digital_library.service
[Unit]
Description=DigitalLibrary Flask App
After=network.target
[Service]
User=ec2-user
Group=ec2-user
WorkingDirectory=/home/ec2-user/Lambda_prj
ExecStart=/usr/bin/python3 app.py
Restart=on-failure
RestartSec=5s
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
# Security hardening
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
[Install]
WantedBy=multi-user.target
[ec2-user@ip-10-0-2-60 ~]$ cd /home/ec2-user/Lambda_prj/
[ec2-user@ip-10-0-2-60 ~]$ pip3 install flask
[ec2-user@ip-10-0-2-60 ~]$ pip3 install requests
[ec2-user@ip-10-0-2-60 ~]$ pip3 install boto3
[ec2-user@ip-10-0-2-60 ~]$ cd /home/ec2-user/Lambda_prj/
[ec2-user@ip-10-0-2-60 Lambda_prj ~]$ sudo systemctl daemon-reload
[ec2-user@ip-10-0-2-60 Lambda_prj~]$ sudo systemctl daemon-reexec
[ec2-user@ip-10-0-2-60 Lambda_prj ~]$ sudo systemctl restart digital_library
[ec2-user@ip-10-0-2-60 Lambda_prj~]$ sudo systemctl status digital_library
● digital_library.service - DigitalLibrary Flask App
Loaded: loaded (/etc/systemd/system/digital_library.service; enabled; preset: disabled)
Active: active (running) since Thu 2025-07-24 19:07:17 UTC; 5s ago
Second server:
[ec2-user@ip-10-0-2-13 ~]$ cd /etc/systemd
[Unit]
Description=DigitalLibrary Flask App
After=network.target
[Service]
User=ec2-user
Group=ec2-user
WorkingDirectory=/home/ec2-user/Lambda_prj
ExecStart=/usr/bin/python3 app.py
Restart=on-failure
RestartSec=5s
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
# Security hardening
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
[Install]
WantedBy=multi-user.target
[ec2-user@ip-10-0-2-13 ~]$ cd /home/ec2-user/Lambda_prj/
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl daemon-reload
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl daemon-reexec
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl restart digital_library
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl status digital_library
● digital_library.service - DigitalLibrary Flask App
Loaded: loaded (/etc/systemd/system/digital_library.service; enabled; preset: disabled)
Active: active (running) since Thu 2025-07-24 19:07:17 UTC; 5s ago
Step15:Check with public ip's Application working or not,Port in the app.py mentioned 5000
First instance Public ip :13.41.229.236
Second instance Public ip
Step16: If you are facing any issues Try these steps
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo chown -R ec2-user:ec2-user /home/ec2-user/Lambda_prj
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo chmod 755 /home/ec2-user/Lambda_prj
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl daemon-reload
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl start digital_library
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl enable digital_library
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl restart digital_library
[ec2-user@ip-10-0-2-13 Lambda_prj]$ sudo systemctl status digital_library
Step17: target group /health 5000 override port
Loader balancer and lister 5000 port
Load balancer add the lister 443
Step18:Route 53 you need add the A record,if any existin A record delete , create new for loadbalancer
using dns
Step21: it will take some time vakatisubbu.xyz 10 to 15 minute synchrize
Step22: Mean while database i have already created, it was shutdown just restart the database
it is starting
Step23: Lambda functions already , i have created Below are reference ,
Already ,i have share Git Repo first line of this page ,you take create lambda function accordingly
Step24:Correspondindg Rest API also need create,All are usign Get functionStep25:1)
/BarrowBooks
Content type : application/json
{
"user_id": "$input.params('user_id')",
"book_id": "$input.params('book_id')"
}
2)
/GetBarrowBooks
Content type : application/json
{
"user_id": "$input.params('user_id')"
}
3)
/GetBarrowHistory
Content type : application/json
{
"user_id": "$input.params('user_id')"
}
4) No input parameter all list of book will populate
/ListBooks
Nothing
5)
/ReturnBooks
Content type : application/json
{
"user_id": "$input.params('user_id')",
"book_id": "$input.params('book_id')"
}
6)
/Signin
Content type : application/json
{
"user_id": "$input.params('user_id')",
"book_id": "$input.params('book_id')"
}
7)
/Signup
Content type : application/json
{
"name": "$input.params('name')",
"mobile": "$input.params('mobile')",
"email": "$input.params('email')",
"password":"$input.params('password')",
"gender": "$input.params('gender')",
"location":"$input.params('location')",
"image": "$input.params('image')"
}
8)
/Welcome
Content type : application/json
{
"user_id": "$input.params('user_id')"
}
Step26:
After database restarted and domain 15minute taking to synchrize, See below webpage login successfully,So Digital Library project completed successfully...
--Thanks
No comments:
Post a Comment