How do I resolve problems connecting to my Amazon DocumentDB cluster?

Last updated: 2020-01-24

I can't connect to my Amazon DocumentDB (with MongoDB compatibility) cluster. Why can't I connect, and how do I troubleshoot connection issues?

Short Description

Amazon DocumentDB is a VPC-only service and doesn't support public endpoints. As a result, you can't connect directly to an Amazon DocumentDB cluster from an environment outside AWS. You can connect to Amazon DocumentDB using the following methods:

  1. Connect from an Amazon Elastic Compute Cloud (Amazon EC2) instance or another AWS service (such as AWS Lambda or Amazon SageMaker) that is in the same Amazon Virtual Private Cloud (Amazon VPC).
  2. Connect from an EC2 instance that is in a different VPC by using VPC peering.
  3. Connect from a machine outside AWS using an SSH tunnel.


Connect from an EC2 instance in the same VPC

1.    Create an EC2 instance in the same VPC that you can SSH into from your source machine.

2.    Confirm that the Amazon DocumentDB cluster's security group has rules that allow connections from the EC2 instance. By default, the security group for the Amazon DocumentDB cluster must allow inbound connections on port 27017.

3.    Connect to your EC2 instance using SSH. See the following example for a Linux instance:

ssh -i "keypairfile.pem" ec2-user@<EC2 DNS endpoint>

4.    Install the mongo shell on EC2 instance, if you haven't already.

5.    Connect to the cluster:

mongo --ssl --host <Cluster endpoint> :27017 --sslCAFile rds-combined-ca-bundle.pem --username <username> --password >password>

MongoDB shell version: 3.2.11

connecting to: <Cluster>:27017/<user>

Connect from an EC2 instance in a different VPC

1.    Create a VPC peering connection from an EC2 instance that is running in a different VPC than the Amazon DocumentDB cluster.

2.    After the peering connection is successful, follow the steps listed previously under Connect from an EC2 instance in the same VPC.

Connect from a machine outside AWS using an SSH tunnel

1.    Set up an SSH tunnel from your local computer to an EC2 instance that is running in the same VPC as your Amazon DocumentDB cluster. For more information, see Connecting to an Amazon DocumentDB Cluster from Outside an Amazon VPC.

ssh -i "keypairfile.pem" -L 27017:<cluster endpoint>:27017 ec2-user@<EC2 tunnel endpoint> -N

This allows you to run commands directly to the local host (27017), and the commands are then sent to the Amazon DocumentDB cluster. However, as a best practice, avoid using this method for production environments or if you use the Amazon DocumentDB cluster as a replica set for your connections. For more information, see Connecting to Amazon DocumentDB as a Replica Set.


If you're using one of these methods, and you're still having trouble connecting, check the following:

  1. The Amazon DocumentDB cluster has at least one instance, and the instance(s) in the cluster are in an available state. If the instances aren't in available states, they can't accept connections.
  2. The source you use to connect to the instance is listed as a source that is authorized to access the cluster in your network access control lists (ACLs), local firewalls, and security group rules.
  3. The correct DNS name or endpoint is used to connect to the Amazon DocumentDB cluster. For troubleshooting DNS and connectivity issues, see Cannot Connect to an Amazon DocumentDB Endpoint.
  4. The user name and password are entered correctly when you connect to the cluster. If you forgot the password, you can reset the password by modifying the Amazon DocumentDB cluster.
  5. The SSL certificate is passed when connecting from a client or an application. By default, TLS configuration is enabled for Amazon DocumentDB clusters. To disable the TLS configuration, create a new custom Amazon DocumentDB cluster parameter group, set the tls parameter to disabled, and then modify the cluster to use the new cluster parameter group. For more information, see Managing Amazon DocumentDB Cluster Parameter Groups.

Did this article help you?

Anything we could improve?

Need more help?