####### Backend-flask project #############
process:: step-1 -->>Create rds with security group "port 3306 and all traffic enabled" -->>now connect sql work bench with your rds credentials --->>now create database and run through workbench
A small Flask backend used for testing MySQL/RDS connectivity and basic CRUD operations on a users table.
This repository contains a minimal Flask app (app.py) that demonstrates connecting to a MySQL-compatible database (local or AWS RDS) and exposes simple REST endpoints to manage users.
- Python 3.8 or newer
- pip
- MySQL / MariaDB server or AWS RDS instance
- git (optional)
- Clone the repository:
git clone https://github.com/CloudTechDevOps/python-backend-testing.git
cd python-backend-testing- Create the database and table (example):
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
);- Configure database connection:
Edit app.py and set the db_config values, or export environment variables before running (example shown for Linux/macOS):
DB_HOST=your-db-host
DB_USER=your-db-user
DB_PASS=your-db-password
DB_NAME=dev- Run the app:
python app.pyThe app listens on port 5000 by default (http://127.0.0.1:5000).
- GET /users — return all users
- GET /users/ — return user by id
- POST /users/add — add a new user (JSON body:
{"name":"..","email":".."}) - PUT /users/update/ — update a user (JSON body with
nameand/oremail) - DELETE /users/delete/ — delete a user
Examples:
curl -X GET http://localhost:5000/users
curl -X POST http://localhost:5000/users/add \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"[email protected]"}'
curl -X PUT http://localhost:5000/users/update/1 \
-H "Content-Type: application/json" \
-d '{"name":"John Updated","email":"[email protected]"}'
curl -X DELETE http://localhost:5000/users/delete/1- Use a production WSGI server (gunicorn, uWSGI) behind a reverse proxy for production.
- For AWS: run the Flask app on an EC2 instance and use an RDS MySQL instance for the DB. Ensure security groups allow the required traffic (DB port 3306 allowed from the app host).
To run the app in background on Linux:
# start
nohup python3 app.py > flask.log 2>&1 &
# check
ps aux | grep app.py
# stop
pkill -f app.pyapp.py— main Flask applicationrequirements.txt— Python dependenciestest.sql— example SQL (if present)