I used to simply use Python to connect to my Postgresql from a Mac with :
username = 'xx' # DB username
password = 'xx' # DB password
host = 'ip' # Public IP address for your instance
port = '5..'
database = 'test'
engine = sqlalchemy.create_engine('postgresql://' + username + ':' + password + '@' + host + ':' + port + '/' + database)
Which works great.
However this will not work on a Cloud Function and we need the Proxy Connection.
I read the docs multiple times, and they are messy and unfocused, transferring you from one link to another.
EDIT TLDR;
Can I simply connect from a Function without a proxy? the amount of things needs to be done and understood to do that consume a lot of time and I simply want my Function to connect to DB like I showed here, without terminal installations and others.
I need help for dumb people that don't understand the if they need to "start the Cloud SQL Auth proxy using TCP sockets, Unix sockets, etc" and just want to connect and build.
I added roles on IAM under App Engine to allow SQL Admin.
I downloaded the proxy using terminal which created a file in the project:
curl -o cloud_sql_proxy
https://dl.google.com/cloudsql/cloud_sql_proxy.darwin.386
I then need to do something like :
./cloud_sql_proxy -instances=INSTANCE_CONNECTION_NAME=tcp:3306
Which I am not sure I understand, I know my connection name, but what is the ./ ? where exactly I run this from ?
I changed the code to :
path="/cloudsql/test-33xxxx:us-central1:user/.s.PGSQL.5432"
engineSKT = sqlalchemy.create_engine('postgresql://' + username + ':' + password + '@/' + database + "?host=" + path)
What else do I need to install using the terminal? the docs are not clear, there are many options (TCP/sock/socket) I am not familiar with those.
Do I need to also install the same things on my
Cloud Functionas well ? not clear.How exactly do I change this code to work ? I understand that I need something like
:socketPath: '/cloudsql/INSTANCE_CONNECTION_NAME'
I do not understand why if under the same project we have a Function and an SQL, Google can't automatically let them connect ? they are obviously were created by the same person and safe to talk.