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.git
cd aws-rds-flask-demo
- Ensure Python 3.x is installed on your system.
- Install the
virtualenv
Python package if not already installed:pip install virtualenv
-
Create a new virtual environment:
py -m venv new-env
Replace
new-env
with 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.txt
Check that all necessary packages are installed:
pip list
-
Edit the
config.py
file 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.txt
to 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! 🎉