"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 ?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠