Connecting to Amazon DocumentDB

This section will go through steps of connecting to DocumentDB cluster from Cloud9 environment. This module uses mongo shell commands and environment variables to connect, which are already deployed as part of cloudformation scripts in Configure AWS Cloud9 workstation.

Start AWS Cloud9 management Console and choose open IDE to launch the AWS Cloud9 environment. You can close the Welcome and AWS Toolkit - QuickStart tabs and adjust your bash terminal window to maximize use of the screen.

Amazon Cloud9 First Run

Retrieve DocumentDB Cluster password

Password for the DocumentDB cluster can be retrived using following command:

echo $docdbPass

Output: Retrive documentDB password Save that password as you will be using it in the following steps.

A best practice is to store database credentials in Secrets Manager. This capability is covered later in the Security lab.

Connecting to Amazon Document DB Cluster

Verify that the Amazon DocumentDB cluster and Primary instance are available on the Amazon Document DB console. Click on the top demo-documentdb link that has the Role of Regional cluster:

Amazon DocumentDB Console Select

Click on the Copy link next to “Connect to this cluster with the mongo shell” to copy the connection string for your cluster.

Amazon DocumentDB Connection String Copy

You can omit the <insertYourPassword> text and paste the connecting string on your Cloud9 environment. Enter the password for Amazon DocumentDB cluster.

Amazon Cloud9 Connection String

The Cloud9 environment should now be connected to the Amazon DocumentDB cluster and you will see the rs0:PRIMARY prompt indicating a successful connection. If you are having trouble connecting, you can step back through the lab ensuring the correct VPC and Security Groups were updated and associated to your cluster. You may also consult Troubleshooting Amazon DocumentDB for help.