I have a flask app in a Paperspace Deployment Docker container. It is connected to a Google Cloud SQL (MySQL).
Here are the variables in the YALM parameters:
env:
- name: CLOUD_SQL_CONNECTION_NAME
value: xx.xx.xx.xx
- name: CLOUD_SQL_USERNAME
value: my_user
- name: CLOUD_SQL_PASSWORD
value: xxxxx
- name: CLOUD_SQL_DATABASE_NAME
value: db_01
And the related code:
HOST =os.environ.get('CLOUD_SQL_CONNECTION_NAME')
USER = os.environ.get('CLOUD_SQL_USERNAME')
PWD = os.environ.get('CLOUD_SQL_PASSWORD')
SQLDB = os.environ.get('CLOUD_SQL_DATABASE_NAME')
CHARSET = os.environ.get('CLOUD_SQL_CHARSET')
SQLALCHEMY_DATABASE_URI = ('mysql+pymysql://{user}:{password}@{connection_name}/{database}').format(user=USER, password=PWD,database=SQLDB, connection_name=HOST)
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
The container is working well if I run it on the local PC, but not in a Paperspace cloud.
The GCloud SQL server never answers, even if I have the Paperspace service's IP address in the authorized IPs from GCould SQL.
The IP has been obtained thanks to a ping to the service endpoint URL.
Here is the error I get from the Paperspace Deployment server.
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '[CLOUD_SQL_CONNECTION_NAME(IP)]' (timed out)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Why the GCloud SQL server never answers? Is there any port or authorization that needs to be activated?