connect from a node server in app engine to mysql in another project

113 views
Skip to first unread message

Emanuel Allen

unread,
Mar 11, 2020, 11:24:16 AM3/11/20
to Google App Engine

environment setup logic: two projects one name projectA and another name projectB. projectA contain the mysql database and projectB contain the app engine node server. 

what i have tried is setting the right permission within projectB in I Am with projectA being the sql client
projectA @ appspot.gserviceaccount.com     App Engine default service accountCloud SQL Client

i also add this to my app.yaml file:

  DB_CONNECTION: mysql
  DB_HOST: localhost
  DB_DATABASE: xxxxxxxxxx
  DB_USERNAME: xxxxxxx
  DB_PASSWORD: xxxxxxxx
  DB_SOCKET: /cloudsql/<project-id>:<region-here>:<db-instance-name>

beta_settings:
  # for Cloud SQL, set this value to the Cloud SQL connection name,
  cloud_sql_instances: <project-id>:<region-here>:<db-instance-name>

here how i tried connecting in my database javascript file:

  con = mysql.createConnection({
    socketPath: "",
    host: "",
    user: "",
    password: ""
  });

with trying to switch between socketPath and host. the socketpath being:
socketPath: `/cloudsql/${process.env.CLOUD_SQL_CONNECTION_NAME}`

format.

I tried and struggle with this but refuse to fail, can anyone give me a solution to this?

Mohammad I (Cloud Platform Support)

unread,
Mar 11, 2020, 11:41:25 PM3/11/20
to Google App Engine

Hello Emanuel, 


Even though it requires project ids and Cloud SQL instance name to investigate the issue further, on a best effort basis I have done some research.


If I have understood it correctly you have MySQL database at projectA and App Engine application at projectB.


In that case I believe you have not done the permission part correctly as described by third party in this StackOverflow thread. As described at the StackOverflow thread, you need to go to the Cloud SQL Console and Click Edit. After that you need to select “Connections” from the left menu and need to add the Project where App Engine application is located following the instructions outlined at Console. In this case the Project is projectB. 


So after going to projectB, you need to select the App Engine default service account which will be “proj...@appspot.gserviceaccount.com”. After that you need to add the “proj...@appspot.gserviceaccount.com” at projectA with the role “Cloud SQL Client” as described at the StackOverflow thread


In addition to that in this StackOverflow thread, it is suggested by a third party to enable both Cloud SQL API and the Cloud SQL Admin API in both projects. 


If still the issue is not resolved or If you have any technical queries or think your issue is related to code, you can post at the Stack Overflow or Server Fault and a community of developers will assist you.


In case there are any technical issues or you would like to request any feature you can report it at the Public Issues by selecting the right component here


Please also note that Google Groups forum is meant for general discussion of the platform, not specific technical issues. You can find more info about Community Support Overview on Google Groups here.

Emanuel Allen

unread,
Mar 16, 2020, 7:36:10 AM3/16/20
to Google App Engine
okay i bang my head on this some more and i get this error:

2020-03-15 09:01:46 default[20200315t045823] Unhandled rejection Error: ER_BAD_DB_ERROR: Unknown database 'db1'

so i'm still confuse on what i'm doing wrong... and why is this so hard!?!?!?!?!

On Wednesday, March 11, 2020 at 11:24:16 AM UTC-4, Emanuel Allen wrote:

Manpreet Sidhu (Google Cloud Support)

unread,
Mar 17, 2020, 12:08:20 AM3/17/20
to google-a...@googlegroups.com
Hi Emanuel,

Getting errors are frustrating and I too would be confused if I didn't fully understand why I was getting the error. May I suggest you report this issue here and someone will be more than happy to assist you. I ask for this because more information is needed to further troubleshoot this issue and by reporting it to the aforementioned place, you will be able to privately share this information with us. I ask for this for your protection.

Please create an Issue Report here and we will be more than happy to help.

Emanuel Allen

unread,
Mar 19, 2020, 4:13:30 PM3/19/20
to Google App Engine
here are screen shoots of doing what was ask of me in this instruction:


Setting up a Cloud SQL instance


no screen shoot of that but i did create it

Find the INSTANCE_CONNECTION_NAME for the instance on the Instance details page. It uses the format PROJECT_ID:REGION:INSTANCE_ID, and is used to identify the Cloud SQL instance you are connecting to.

Screenshot_2020-03-19 db1 Overview - My First Project - Google Cloud Platform.png


Enable the Cloud SQL Admin API, if you haven't already done so:

i click it for both projects

This service account must have the correct IAM permissions to successfully connect. Unless otherwise configured, the default service account is in the format service-PROJECT_NUMBER@gae-api-prod.google.com.iam.gserviceaccount.com

When connecting resources in two different projects, make sure that both projects have enabled the correct IAM roles and have given the service account the correct permissions.

Ensure that the service account for your service has one of the following IAM roles:


Screenshot_2020-03-19 IAM – IAM Admin – My First Project – Google Cloud Platform.png


Screenshot_2020-03-19 Cloud Shell(1).png




and here the error message:

Screenshot_2020-03-19 Cloud Shell.png

i been stuck on this project for weeks and i hate that it's this complicated or even worst it's not complicated at all but it just not conveying to me correctly of what i might be doing wrong. The frustration is real, i never blame a tool for not knowing how to use it correctly but this is making me hate google. you would think i could find a lot of resource on google cloud dealing with  this issues on youtube but i don't and it suck and no other where can i find any help or how to but that same link that i been going over and over. if anyone see what i'm doing wrong or if there is a google emlpoyee that i can give access to my account to show me how to do it. i will high appreciate it. 






On Wednesday, March 11, 2020 at 11:24:16 AM UTC-4, Emanuel Allen wrote:

yananc

unread,
Mar 20, 2020, 6:19:48 PM3/20/20
to google-a...@googlegroups.com

Hello Emanuel,


Thank you for the screenshot you provided. However, troubleshooting the specific issue might require more detailed information and investigation into your project. Is it possible for you to report the issue through the link in order to get further support on the issue, which would enable the sharing of sensitive information about your project as well as make it much easier to locate the root cause of the error? We will be more than happy to assist you. Thank you for your consideration.


Reply all
Reply to author
Forward
Message has been deleted
0 new messages