Search code examples
amazon-web-servicesubuntuaws-documentdb

Not able to connect to AWS DocumentDB from my ubuntu EC2 machine


I can't connect to my Amazon DocumentDB from my amazon EC2 ubuntu machine? I've checked the security of the Amazon DocumentDB and it's currently assigned to the default which has "all traffic".

I've tried the following command, straight out of the AWS instances page although I receive the error message included below.

I've followed this aws guide https://docs.aws.amazon.com/documentdb/latest/developerguide/getting-started.connect.html

Mongo shell command from the EC2 ubuntu machine

mongo --ssl --host mydatabasename.23scnncsd3.eu-west-1.docdb.amazonaws.com:27017 --sslCAFile rds-combined-ca-bundle.pem --username webuser --password mypassword

The error message I receive from within the ubuntu command prompt is below

Error message

MongoDB shell version v3.6.11
connecting to: mongodb://mydatabasename.23scnncsd3.eu-west-1.docdb.amazonaws.com:27017/?gssapiServiceName=mongodb
2019-03-11T21:39:37.587+0000 W NETWOK  [thread1] Failed to connect to 172.31.45.184:27017 after 5000ms milliseconds, giving up.
2019-03-11T21:39:37.595+0000 E QUERY    [thread1] Error: couldn't connect to server mydatabasename.23scnncsd3.eu-west-1.docdb.amazonaws.com:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed

Am I doing something wrong? Any help appreciated!

Many thanks,

Update

aws screen shot


Solution

  • Amazon DocumentDB deploys clusters within a VPC, which act as a strong network boundary to other VPCs and the Internet. When you are connecting to your cluster, ensure that the client machine is in the same region and the same VPC as the cluster.

    Alternatively, if your development environment is in a different Amazon VPC, you can also use VPC Peering and connect to your Amazon DocumentDB cluster from another Amazon VPC in the same region or a different region.

    For more information on troubleshooting: https://docs.aws.amazon.com/documentdb/latest/developerguide/troubleshooting.html

    Connecting to an Amazon DocumentDB cluster from outside a VPC: https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html