Sea*_*256 1 mongodb amazon-web-services node.js aws-documentdb
我按照此处的说明设置了 SSH 隧道以进行外部连接: https: //docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html
一旦建立了隧道,我就可以使用 GUI 客户端 Robomongo 和“Studio 3T”进行连接。这样就验证了 ec2 机器确实具有访问权限并且我的 SSH 隧道正在工作。
但尽管如此,NodeJS 对这种连接并不满意。根据我的配置,我收到两个错误之一。
配置1:
const url = 'mongodb://root:some-password@localhost:27017?ssl=true&replicaSet=rs0&readPreference=secondaryPreferred';
const ca = [fs.readFileSync('./rds-combined-ca-bundle.pem')];
const options = {
sslValidate: false, // you will see why in the next config
sslCA: ca,
useNewUrlParser: true,
useUnifiedTopology: true,
};
const client = new MongoClient(url, options);
Run Code Online (Sandbox Code Playgroud)
几秒钟后我得到:
(node:7640) UnhandledPromiseRejectionWarning: MongoServerSelectionError: connect ENETUNREACH 172.31.26.210:27017
at Timeout._onTimeout (/Volumes/foo/source/node_modules/mongodb/lib/core/sdam/topology.js:430:30)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
Run Code Online (Sandbox Code Playgroud)
配置2:
const url = 'mongodb://root:some-password@localhost:27017?ssl=true&replicaSet=rs0&readPreference=secondaryPreferred';
const ca = [fs.readFileSync('./rds-combined-ca-bundle.pem')];
const options = {
sslValidate: true, // now this is true
sslCA: ca,
useNewUrlParser: true,
useUnifiedTopology: true,
};
const client = new MongoClient(url, options);
Run Code Online (Sandbox Code Playgroud)
几秒钟后我得到:
(node:7682) UnhandledPromiseRejectionWarning: MongoServerSelectionError: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:docdb-2020-07-14-23-38-05.cluster-cpapk5zw6fa0.us-west-2.docdb.amazonaws.com, DNS:docdb-2020-07-14-23-38-05.cluster-ro-cpapk5zw6fa0.us-west-2.docdb.amazonaws.com, DNS:docdb-2020-07-14-23-38-05.cpapk5zw6fa0.us-west-2.docdb.amazonaws.com
at Timeout._onTimeout (/Volumes/foo/source/node_modules/mongodb/lib/core/sdam/topology.js:430:30)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
Run Code Online (Sandbox Code Playgroud)