Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Python Backend Testing (flask_rds_user_api)

  • 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> -p

example:

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;

Deploy Flask Backend on EC2

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.py

To run Flask in background:

nohup allows your app to continue running even after terminal disconnect:

nohup python3 flask_rds_user_api.py > flask.log 2>&1 &
tail -f flask.log

To check if the app is running:

ps aux | grep flask_rds_user_api.py

To 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 -i

✅ Step 8: API Methods and Testing

Flask API Supports:

  • GET /users → Fetch all users
  • GET /users/<id> → Fetch single user by ID
  • POST /users/add → Add a new user
  • PUT /users/update/<id> → Update user
  • DELETE /users/delete/<id> → Delete user

Example curl Commands:  Run this commands in EC2  backend server

GET all users:

curl -X GET http://localhost:5000/users/1

GET single user:

curl -X GET http://localhost:5000/users

POST - 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages