在单独的项目中从App Engine连接到GCP Cloud SQL [英] Connecting to GCP Cloud SQL from App Engine in separate project

查看:215
本文介绍了在单独的项目中从App Engine连接到GCP Cloud SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一个单独的GCP项目中的GCP Google App Engine灵活环境连接到GCP Postgres Cloud SQL实例。我正在使用Python。

I am trying to connect to a GCP Postgres Cloud SQL instance from a GCP Google App Engine flexible environment in a separate GCP project. I am using Python.

说明指示这要求将默认的App Engine服务帐户添加为Postgres Cloud SQL项目中的IAM成员。

The instructions indicate that this requires adding the default App Engine service account as an IAM member in the Postgres Cloud SQL project.

文档继续说明:


一旦部署,您的应用程序将使用内置在App Engine灵活环境中的Cloud SQL代理与您的Cloud SQL实例进行通信。

Once deployed, your application uses the Cloud SQL Proxy that is built in to the App Engine flexible environment to communicate with your Cloud SQL instance.

但是,我没有从GAE成功连接到Cloud SQL的运气。我已经尝试了多种主机地址(例如 localhost < external-ip-address> / cloudsql /< INSTANCE_CONNECTION_NAME> 等),但似乎无济于事。

However, I've had no luck successfully connecting to Cloud SQL from GAE. I've tried several varieties of host addresses (e.g. localhost, <external-ip-address>, /cloudsql/<INSTANCE_CONNECTION_NAME>etc.) but nothing seems to work.

我想到了几个问题:

Several questions come to mind:


  • 我是否需要手动为GAE实例提供服务帐户密钥?

  • Do I need to manually provide a service account key to the GAE instance?

用于连接参数或DSN字符串的Cloud SQL实例的实际主机位置是什么?尽管我对此没有运气,但是文档引用了 / cloudsql /< INSTANCE_CONNECTION_NAME>

What is the actual host location of the Cloud SQL instance for connection parameters or DSN strings? The docs refer to /cloudsql/<INSTANCE_CONNECTION_NAME> though I've had no luck with this.

我需要创建一个共享网络来链接项目吗?

Do I need to create a shared network to link the projects?

推荐答案

我刚刚复制了您的用例场景,并成功地将一个项目的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.

这篇关于在单独的项目中从App Engine连接到GCP Cloud SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆