Thanks Jiasheng Yang,
Thanks you for your timely help.
I followed the steps as given below and it helps me to resolve the issue:
1. Ran "gcloud auth application-default login "
This gave a warning message given below :
"You are running on a Google Compute Engine virtual machine.
The service credentials associated with this virtual machine
will automatically be used by Application Default
Credentials, so it is not necessary to use this command.
If you decide to proceed anyway, your user credentials may be visible
to others with access to this virtual machine. Are you sure you want
to authenticate with your personal account?
Do you want to continue (Y/n)?"
I Entered 'Y", it gives a URL, to generate a token.
I generated the token and given in the command prompt.
2. Ran the Proxy setting :
a. download proxy using the below url
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
b. chmod +x cloud_sql_proxy
c. sudo ./cloud_sql_proxy -dir=/cloudsql -instances=<INSTANCE_CONNECTION_NAME> &
It shows the confirmation of running of proxy
3. Change the
create_engine('postgresql+psycopg2://DB-USERID:PASSWORD@/DATABASE-NAME?host=/cloudsql/<INSTANCE_CONNECTION_NAME>')
After doing all the above 3-steps , it works for me. to runn my python flax application with Postgresql , work in coloud project.
4. Done the below change to make it work after deployment.
#[START env]
env_variables:
# Replace user, password, database, and instance connection name with the values obtained
# when configuring your Cloud SQL instance.
SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://DATABASE-USER-ID:PASSWORD@/DATABASE-NAME?host=/cloudsql/<INSTANCE_CONNECTION_NAME>
#[END env]
#[START cloudsql_settings]
# Replace project and instance with the values obtained when configuring your
# Cloud SQL instance.
beta_settings:
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>
#[END cloudsql_settings]
5. Done the below change in my main.py to get the environment variable:
import os
engine = create_engine(os.environ['SQLALCHEMY_DATABASE_URI'])
Session = sessionmaker(bind=engine)
Just want know , are the steps followed to make it work correct or is there any other steps there to make it work.
Thanks
Binaya