This project demonstrates how to integrate a Flask web application with an AWS RDS MySQL database. It covers the steps required to set up a virtual environment, configure the database, and run the Flask server. This example is designed to help developers understand the fundamentals of using cloud-hosted databases with Flask applications.
git clone https://github.com/SAGE-Rebirth/aws-rds-flask-demo.gitcd aws-rds-flask-demo- Ensure Python 3.x is installed on your system.
- Install the
virtualenvPython package if not already installed:pip install virtualenv
-
Create a new virtual environment:
py -m venv new-env
Replace
new-envwith your preferred name. -
Activate the virtual environment:
- On Windows:
new-env\Scripts\activate
- On macOS/Linux:
source new-env/bin/activate
- On Windows:
Install all required Python packages:
pip install -r requirements.txtCheck that all necessary packages are installed:
pip list-
Edit the
config.pyfile to update the RDS endpoint. Use the following format:mysql+pymysql://<username>:<password>@<rds-database-endpoint>/<database-name>- Replace
<username>,<password>,<rds-database-endpoint>, and<database-name>with your database credentials. - Note: Do not include angle brackets (
<>) when entering the values.
- Replace
-
Execute the SQL queries in
table-query.txtto set up the required database tables. Modify the queries if necessary, but ensure corresponding changes are reflected in the code.
Run the following command to start the server:
py run.py- Environment Activation: Ensure the virtual environment is activated before executing any Python commands or installing packages.
- Database Configuration: Double-check the credentials and endpoint to avoid connection issues.
- SQL Queries: Execute the provided queries carefully to avoid schema mismatches with the application code.
Happy Coding! 🎉