英文:
connect ENOENT error when connecting to Google Cloud SQL from App Engine / localhost
问题
I have a next.js-strapi v4 app hosted on google cloud app engine.
The database is postgreSql and hosted on google cloud sql.
The files are also hosted on gcp.
Since the deployment to Google App Engine is missing from the strapi v4 documentation, I used that guide on medium.
when I run the app using:
gcloud app deploy app.yaml
I get this error:
debug: ⛔️ Server wasn't able to start properly.
error: connect ENOENT /cloudsql/INSTANCE_CONNECTION_NAME/.s.PGSQL.5432
at PipeConnectWrap.afterConnect
this is the app.yaml:
runtime: nodejs16
instance_class: F2
env_variables:
NODE_ENV: 'production'
beta_settings:
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>
this is database.js:
module.exports = ({ env }) => ({
connection: {
client: "postgres",
connection: {
host: /cloudsql/${env('INSTANCE_CONNECTION_NAME')}
,
port: env.int("DATABASE_PORT", 5432),
database: env("DATABASE_NAME", "strapi"),
user: env("DATABASE_USERNAME", ""),
password: env("DATABASE_PASSWORD", ""),
},
},
});
This is what I have already did:
- enable the Cloud SQL Admin API
- add Cloud SQL Client role to my App Engine default service account
- expose the virtual machine ip and my local ip to the Authorized networks of the database
- run "gcloud auth application-default login" on the google cloud sdk
- made a successful connectivity test with my ip using the CONNECTIVITY TESTS tab
I also tried to connect to the gcp database from my local app but got the same error.
thanks for any help!
英文:
I have a next.js-strapi v4 app hosted on google cloud app engine.
The database is postgreSql and hosted on google cloud sql.
The files are also hosted on gcp.
Since the deployment to Google App Engine is missing from the strapi v4 documentation, I used that guide on medium.
when I run the app using:
gcloud app deploy app.yaml
I get this error:
debug: ⛔️ Server wasn't able to start properly.
error: connect ENOENT /cloudsql/INSTANCE_CONNECTION_NAME/.s.PGSQL.5432
at PipeConnectWrap.afterConnect
this is the app.yaml:
runtime: nodejs16
instance_class: F2
env_variables:
NODE_ENV: 'production'
beta_settings:
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>
this is database.js:
module.exports = ({ env }) => ({
connection: {
client: "postgres",
connection: {
host: `/cloudsql/${env('INSTANCE_CONNECTION_NAME')}`,
port: env.int("DATABASE_PORT", 5432),
database: env("DATABASE_NAME", "strapi"),
user: env("DATABASE_USERNAME", ""),
password: env("DATABASE_PASSWORD", ""),
},
},
});
This is what I have already did:
- enable the Cloud SQL Admin API
- add Cloud SQL Client role to my App Engine default service account
- expose the virtual machine ip and my local ip to the Authorized networks of the database
- run "gcloud auth application-default login" on the google cloud sdk
- made a successful connectivity test with my ip using the CONNECTIVITY TESTS tab
I also tried to connect to the gcp database from my local app but got the same error.
thanks for any help!
答案1
得分: 1
solution 1
你必须通过云SQL身份验证代理授予访问权限。
配置云SQL与App Engine标准环境的文档
solution 2
- 首先,您必须在GCP上创建虚拟专用云(VPC)。
- 然后将您的云SQL实例IP添加到VPC网络对等连接。
- 接着,在您的VPC中创建一个具有28 CIDR范围子网的无服务器VPC访问连接器。
- 最后,在app.yaml中提及您的适配器名称。
如果您正在使用App Engine弹性环境进行托管,无需创建无服务器VPC访问连接器。
英文:
solution 1
you have to grants access through cloud sql auth proxy
documentation for config cloud sql with app engine standard environment
solution 2
- first you have to create virtual private cloud (VPC) from gcp.
- then add you cloud sql instance ip to VPC network peering
- then create Serverless VPC access connector with 28 CIDR range
subnet in your VPC - finally mention your adapter name in app.yaml
configure serverless vpc access connector
if you are host using app engine flexible environment no need to creatre serverless VPC access connector
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论