"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?
asked 8 months ago442 views
1 Answer
0

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.

Mihai A
answered 8 months ago
  • 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 ?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions