- update
sudo dnf update -y- Install MySQL client
sudo dnf install mariadb105 -y
mysql --version- Connect to RDS
mysql -h <your-rds-endpoint> -u <username> -pexample:
mysql -h mydb.xxxxxx.ap-south-1.rds.amazonaws.com -u admin -p- Run the following SQL commands:
CREATE DATABASE dev;
USE dev;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE
);
SELECT * FROM dev.users;yum install python3-pip -y
pip3 install flask mysql-connector-python
yum install git -y
git clone https://github.com/arumullayaswanth/Python-backend-testing.git
cd Python-backend-testing
python3 flask_rds_user_api.pynohup allows your app to continue running even after terminal disconnect:
nohup python3 flask_rds_user_api.py > flask.log 2>&1 &
tail -f flask.logTo check if the app is running:
ps aux | grep flask_rds_user_api.pyTo stop it:
pkill -f flask_rds_user_api.py✅ Step 7: Reconnect to EC2 backend server once again
Now your application is running And don't Exit your application and take the new window and connect once again your EC2 backend server and run these commands again.
Open a new terminal window and SSH back into EC2:
ssh -i "your-key.pem" ec2-user@<EC2 Public IP>
sudo -iGET /users→ Fetch all usersGET /users/<id>→ Fetch single user by IDPOST /users/add→ Add a new userPUT /users/update/<id>→ Update userDELETE /users/delete/<id>→ Delete user
GET all users:
curl -X GET http://localhost:5000/users/1GET single user:
curl -X GET http://localhost:5000/usersPOST - Add user:
curl -X POST http://localhost:5000/users/add \
-H "Content-Type: application/json" \
-d '{"name":"John Doe", "email":"john@example.com"}'PUT - Update user:
curl -X PUT http://localhost:5000/users/update/1 \
-H "Content-Type: application/json" \
-d '{"name": "John Updated", "email": "john.updated@example.com"}'DELETE - Remove user:
curl -X DELETE http://localhost:5000/users/delete/1