[英]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环境)时发现了连接问题,这里总结了您必须执行的主要步骤:
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>
。 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
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. (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.