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.
Password for the DocumentDB cluster can be retrived using following command:
Output: 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.
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:
Click on the Copy link next to “Connect to this cluster with the mongo shell” to copy the connection string for your cluster.
You can omit the <insertYourPassword> text and paste the connecting string on your Cloud9 environment. Enter the password for Amazon DocumentDB cluster.
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.