且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在单独的项目中从App Engine连接到GCP Cloud SQL

更新时间:2022-12-25 11:01:23

我刚刚复制了您的用例场景,并成功地将一个项目的Cloud SQL数据库与另一个项目的Cloud App Engine连接起来。

I just replicated your use case scenario and I successfully connected a Cloud SQL database from a project with a Cloud App Engine from another project.

重现此步骤的步骤是以下内容:

The steps to reproduce this are the followings:


  • 使用公共IP创建Cloud SQL Postgresql数据库。

  • Created a Cloud SQL Postgresql Database with public Ip.

为我的应用程序创建表

在我要托管App Engine端的第二个项目中启用Cloud SQL API

使用此 Google云存储

使用该应用授予该项目的服务帐户权限使用Cloud SQL for PostgreSQL指南

Give permission to the service account of the project with the App Engine in the project with the Cloud SQL following this Using Cloud SQL for PostgreSQL guide

在复制过程中,您可能遇到的问题。可能您没有启用第二个项目(仅托管App Engine的项目)的API。

During my reproduction foud the possible issue that you have encountered. Probably you didn't enable the API of the second project (the one hosting just the App Engine).

要验证这一点,您只需要进入托管该项目的计算机即可。应用引擎,然后运行 docker ps -a 以获取托管 cloud-sql-proxy 的Docker容器的ID。 。然后使用该ID运行 docker logs -f ID_OF_THE_CONTAINER ,您将看到Cloud SQL代理中是否有错误。如果您禁用了API,则只需启用它并再次部署即可。

To verify this you just need to ssh into the machine hosting the app engine, then run docker ps -a to get the id of the docker container hosting the cloud-sql-proxy. Then using that id run docker logs -f ID_OF_THE_CONTAINER and you will see if you have an error in your Cloud SQL proxy. If you have the API disabled just enable it and deploy again.