使用Sequelize通过SSL连接到CloudSQL

时间:2019-05-14 23:31:47

标签: node.js sequelize.js google-cloud-sql

我需要将Lambda上的Node js应用程序连接到Google Cloud SQL中的PSQL数据库。

node js应用程序使用Sequelize,我在寻找有关如何在sequelize上显示SSL信息的任何指南时遇到了麻烦。

这是Cloud SQL要我指定的内容:

  psql "sslmode=verify-ca sslrootcert=server-ca.pem \
      sslcert=client-cert.pem sslkey=client-key.pem \
      hostaddr=[HOST ID] \
      port=5432 \
      user=postgres dbname=postgres"

这是我目前在节点js应用程序上保持超时的内容:

const sequelize = new Sequelize(
  'postgres',
  'postgres',
  'password',
  {
    host: '[HOST ID]',
    dialect: 'postgres',
    dialectOptions: {
      ssl: {
        key: cKey,
        cert: cCert,
        ca: cCA,
      }
    }
  },
);

这是我收到的错误消息:

Unhandled rejection SequelizeConnectionError: connect ETIMEDOUT 35.232.250.60:5432
    at connection.connect.err (/Users/stephanielee/Desktop/blag/dist/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:154:24)
    at Connection.connectingErrorHandler (/Users/stephanielee/Desktop/blag/dist/node_modules/pg/lib/client.js:174:14)
    at Connection.emit (events.js:182:13)
    at Connection.EventEmitter.emit (domain.js:442:20)
    at Socket.reportStreamError (/Users/stephanielee/Desktop/blag/dist/node_modules/pg/lib/connection.js:72:10)
    at Socket.emit (events.js:182:13)
    at Socket.EventEmitter.emit (domain.js:442:20)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

0 个答案:

没有答案