"Connect failed" when trying to connect to the DocumentDB cluster from AWS C9

0

In order to insert data to a cluster with a python script, I try to connect to my cluster DocumentDB on AWS from AWS C9 with this tutorial. But every time I try to connect I get connection failed after 6 attempts:

    (scr_env) me:~/environment/sephora $ mongo --ssl --host xxxxxxxxxxxxx:xxxxx --sslCAFile rds-combined-ca-bundle.pem --username username --password mypassword
    MongoDB shell version v3.6.3
    connecting to: mongodb://xxxxxxxxxxxxx:xxxxx/
    2022-03-22T23:12:38.725+0000 W NETWORK  [thread1] Failed to connect to xxx.xx.xx.xxx:xxxxx after 5000ms milliseconds, giving up.
    2022-03-22T23:12:38.726+0000 E QUERY    [thread1] Error: couldn't connect to server xxxxxxxxxxxxx:xxxxx, connection attempt failed :
    connect@src/mongo/shell/mongo.js:251:13
    @(connect):1:6
    exception: connect failed

I tried to remove the lock file to repair the instance as they do in this answer:

    (scr_env) me:~/environment/sephora $ sudo rm /var/lib/mongodb/mongod.lock
    rm: cannot remove '/var/lib/mongodb/mongod.lock': No such file or directory

I know that the "fail to connect" error can be caused by a lot of reasons, but usually they are:

  • the service (mongo) might not be running on the destination server;
  • the service (mongo) might be listening on a different port number;
  • the service (mongo) might be protected by a firewall somewhere on the destination.

So how can I ensure that:

  • mongo is running on the destination host?
  • mongo is listening on the defined port?
  • I've allowed to connect to the destination host on the defined port from the IP address or network range you're running the command to connect?
已提问 2 年前1489 查看次数
1 回答
1

Hi. Make sure the Cloud9 instance is in the same VPC as Amazon DocumentDB cluster. Then double check the security group attached with DocumentDB, it should have an inbound rule to allow connections with source the C9 security group. I recommend following the getting started guide from the DocumentDB documentation.

AWS
Mihai A
已回答 2 年前
  • Thank you very much for your reference @Mihai yet I struggle with installing the mongo shell in my AWS Cloud9.

    Indeed, it seems I can't create the repository file with the echo -e "[mongodb-org-4.0] \nname=MongoDB Repository\nbaseurl=... it returns: mongodb-org-4.0.repo: No such file or directory

    Furthermore, when I tried to install the mongo shell with sudo yum install -y mongodb-org-shell which I didn't had, and which I installed, it returns repolist: 0

  • What's the full 'echo' command you're running ?

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则