How to connect to Amazon DocumentDB from Node.js

Gor*_*ove 3 amazon-web-services node.js amazon-elastic-beanstalk aws-documentdb-mongoapi aws-documentdb

How do I connect to Amazon's new DocumentBD database from node.js (In this case, using an out-of-the-box Elastic Beanstalk setup.)

This is my code, copied from the docs (with some values altered for privacy). It just times out and the eventual value of 'err' is 'true'. What did I miss? How can I get a better error?

var MongoClient = require('mongodb').MongoClient,fs = require('fs');
var ca = [fs.readFileSync("rds-combined-ca-bundle.pem")];
var connection_string = "mongodb://USERNAME:PASSWORD@docdb-2019-04-23-12-55-44.cluster-abcdefghij.eu-west-1.docdb.amazonaws.com:27017/?ssl=true&&replicaSet=rs0&readPreference=secondaryPreferred";

MongoClient.connect(
        connection_string, {
            sslValidate: true,
            sslCA: ca,
            useNewUrlParser: true
        },
        function (err,client) {
            console.log(err+" , "+ client);
        });
Run Code Online (Sandbox Code Playgroud)

Here's hoping somebody knows.

hep*_*ump 5

超时通常表明安全组配置不正确。检查您的 DocumentDB 入站安全组配置,以确保允许来自源的流量到达您的 DocumentDB 实例。