Here is the gist of my GCP cloud function 'app':
main.py
import sqlalchemy import logging import os from time import perf_counter def main(data, context): log = logging.getLogger("course_gen") db = sqlalchemy.create_engine( sqlalchemy.engine.url.URL( drivername="mysql+pymysql", username=os.environ.get("DB_USER"), password=os.environ.get("DB_PASS"), host="**.***.**.***", # this is actually the public IP of my cloud mysql instance port=3306, database="table_name" ), pool_size=5, max_overflow=2, pool_timeout=30, pool_recycle=1800 ) with db.connect() as cursor: start_time = perf_counter() if __name__ == '__main__': main('data', 'context') and here is the corresponding overview of my Cloud MySQL instance from which I copied the IP:
the port kwarg was a bit confusing but from what I've inferred from posts like this, it's always 3306.
Basically when I run my cloud function locally, I expect it to be able to connect to the live GCP MySQL instance I have provisioned but the full error I'm getting is:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on (timed out)") 