简体   繁体   English

如何允许Google App Engine访问Google Cloud PostgreSQL

[英]How to allow Google App Engine access Google Cloud PostgreSQL

I've found problem my node.js in Google App Engine, as it cannot connect to Google Cloud PostgreSQL: 我在Google App Engine中发现我的node.js问题,因为它无法连接到Google Cloud PostgreSQL:

Unhandled rejection SequelizeBaseError: connect ETIMEDOUT ***.***.***.***:5432
at (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:111)
at Connection.<anonymous> (/app/node_modules/pg/lib/client.js:176)
at emitOne (events.js:96)
at Connection.emit (events.js:188)
at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:59)
at emitOne (events.js:96)
at Socket.emit (events.js:188)
at emitErrorNT (net.js:1281)
at _combinedTickCallback (internal/process/next_tick.js:74)
at process._tickCallback (next_tick.js:98)

I'm not sure how to add an IP address in the following (maybe I missed something to configure inside Google Cloud SQL). 我不确定如何在下面添加IP地址(也许我错过了在Google Cloud SQL中进行配置的内容)。

在此处输入图片说明

There is some really nice documentation on how to connect App Engine applications to Cloud SQL instances . 关于如何将App Engine应用程序连接到Cloud SQL实例,有一些非常不错的文档。 There you can find detailed steps on how to let your applications access the Cloud SQL instances, for each of the supported programming and SQL languages, both in local development and production environments. 在那里,您可以找到有关在本地开发和生产环境中如何为每种受支持的编程语言和SQL语言让应用程序访问Cloud SQL实例的详细步骤。

Assuming your connection issues are found when deploying your application to production (ie App Engine environment), here you have a summary of the main steps you will have to perform: 假设在将应用程序部署到生产环境(即App Engine环境)时发现了连接问题,这里总结了您必须执行的主要步骤:

  1. Get the full name of you Cloud SQL instance with the command gcloud sql instances describe [INSTANCE_NAME] . 使用命令gcloud sql instances describe [INSTANCE_NAME]获取您的Cloud SQL实例的全名。 It should be of the type <PROJECT_ID>:<REGION>:<INSTANCE_NAME> . 它应该是<PROJECT_ID>:<REGION>:<INSTANCE_NAME>
  2. Grant access to App Engine using the service account associated with your App Engine application. 使用与您的App Engine应用程序关联的服务帐户授予对App Engine的访问权限。 It should have the Cloud SQL Client or Cloud SQL Editor roles. 它应该具有Cloud SQL ClientCloud SQL编辑器角色。
  3. Define the environment variables and beta settings for your SQL instance in the app.yaml file. app.yaml文件中为您的SQL实例定义环境变量beta设置

(Add this code, edited to fit your parameters, to the app.yaml file): (将此代码(已编辑以适合您的参数)添加到app.yaml文件中):

env_variables:
  SQL_USER: <YOUR_CLOUD_SQL_USER>
  SQL_PASSWORD: <YOUR_CLOUD_SQL_PASSWORD>
  SQL_DATABASE: <YOUR_CLOUD_SQL_DATABASE>
  INSTANCE_CONNECTION_NAME: <INSTANCE_CONNECTION_NAME>   # With format as <PROJECT_ID>:<REGION>:<INSTANCE_NAME>

beta_settings:
  cloud_sql_instances: <INSTANCE_CONNECTION_NAME>   # With same format
  1. Add a Node.js PostreSQL client library to your application using the package.json file. 使用package.json文件将Node.js PostreSQL客户端库添加到您的应用程序。 The documentation suggests using Knex.js and pg , but presumably you will be able use the one of your choice. 该文档建议使用Knex.jspg ,但大概可以使用您选择的一种。

(Add this code to the package.json file): (将此代码添加到package.json文件中):

"dependencies": {
  "async": "2.5.0",
  "express": "4.15.4",
  "knex": "0.13.0",
  "pg": "7.3.0",
  "prompt": "1.0.0"
},

Once you have set the proper configuration for your application, you can have a look at this sample Node.js code . 为应用程序设置正确的配置后,您可以查看此示例Node.js代码 In order to find any missing item in your main script. 为了找到您的主脚本中的任何丢失的项目。

If you deploy your application now, it should work as a charm. 如果您现在部署应用程序,它应该很吸引人。

PS: Bear in mind that, as App Engine and Cloud SQL are two products of the Google Cloud Platform family, there is no need to authorize external networks in your Cloud SQL instance, so you can forget about that part too. PS:请记住,由于App Engine和Cloud SQL是Google Cloud Platform系列的两个产品,因此无需在您的Cloud SQL实例中授权外部网络,因此您也可以省去这部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google云端:存储和App Engine - Google Cloud: Storage and App Engine 无法从我的App Engine访问Google Cloud SQL数据库 - Cannot access Google Cloud SQL database from my App Engine Google Cloud App Engine上的Nodejs应用未启动 - Nodejs app on Google Cloud App Engine not starting 如何从谷歌云应用引擎与外部 exe 程序通信? - How to communicate with an external exe program from an google cloud app engine? 如何将数据从应用程序引擎保存到数据存储谷歌云 javascript - How to save data from app engine to datastore google cloud javascript 如何在谷歌云应用引擎中修复“找不到模块'dotenv'”? - how to fix "Can not find module 'dotenv'" in google cloud app engine? 如何在 Google Cloud App Engine for Node.js 中使用 Memcache - How to use Memcache in Google Cloud App Engine for Node.js 如何使用oAuth2在服务器之间进行通信(Google Cloud Engine-&gt; Google App Engine) - How to communicate between servers (Google Cloud Engine -> Google App Engine) using oAuth2 将 Google App Engine 连接到 GCE 上的 PostgreSQL 数据库 - Connect Google App Engine to PostgreSQL database on GCE Google App引擎和Cloud SQL连接被拒绝 - Google App engine and Cloud sql connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM