Step 3. Connect to MongoDB Nodes - MongoDB on AWS

Step 3. Connect to MongoDB Nodes

Once the AWS CloudFormation template has successfully created the stack, all the MongoDB nodes will be running with the software installed in your AWS account. To connect to any of the MongoDB nodes, use SSH to connect to the bastion host instance. In the Amazon EC2 console, choose the instance, and then choose Connect.


                Connecting to a MongoDB node

Figure 7: Connecting to a MongoDB node

Once you connect to the bastion host instance by using SSH, you can connect to any of the MongoDB nodes in a similar fashion (choose the node, and then choose Connect to find the SSH command).

Important

Copying the private key (.pem) file for connecting MongoDB nodes is discouraged. Instead, follow this blog post to add the private key to your SSH agent and then log in to the bastion instance with SSH agent forwarding enabled. Refer to the following examples:

Log in to the bastion host with SSH agent forwarding enabled:

ssh -A ec2-user@Bastion-public-ip

Add a private key to the SSH agent:

ssh-add -K mykey.pem

Note that all the MongoDB nodes are launched with an IAM role that grants them privileges to create and delete Amazon DynamoDB tables, to access Amazon Simple Storage Service (Amazon S3), to create and delete Amazon EC2 instances, and so on. You can modify the policy by using the IAM console. For details about the benefits of IAM roles, see Using IAM Roles to Delegate Permissions to Applications that Run on Amazon EC2 in the AWS documentation.