Looking for Senior AWS Serverless Architects & Engineers?
Let's TalkThis article is part of a series 😃. It’s up to you how you want to proceed, either reading this whole thing first and coming back after you need too or starting from the beginning.
- Part 1: SSH Tunnel — AWS EC2
- Part 2: Creating an AWS EC2 instance
- Part 3: Fully Managed MongoDB — DocumentDB
- Part 4: Creating an AWS DocumentDB cluster
Let’s create a cluster!
Open up the AWS console and let’s get cracking.
First let’s select Parameter Groups and turn off some additional security for demo purposes.
NOTE: Do this step before creating the DocumentDB Cluster
Once you create the Parameter Group, click on TLS and TTL_Monitor and flip the switch to disabled.
Time to launch an Amazon DocumentDB Cluster.
Note: Set Instance Class as db.r4.large and Number of Instances to 1. These are the cheapest settings that DocumentDB currently supports.
Click Show Advanced Settings, we need to add our new Parameter Group to the DocumentDB cluster we are creating.
Easy enough. Now hit Create Cluster.
Perfect 🎉. Now we have a DocumentDB cluster spinning up. When the cluster is finished creating we should be able to connect to the new cluster and go from there, right?
Let’s try to connect.
Looks like we can’t connect. Why is this?
Currently, DocumentDB does not support public endpoints meaning we can not directly connect to our cluster from our laptop. What do we do? Setup an SSH Tunnel, cool let’s do that.
SSH Tunnel
Setup an SSH Tunnel
To keep the articles modular, I’ve created a separate article which focuses on what a SSH Tunnel does and how to create an EC2 instance on AWS which we will use as our SSH Tunnel. This same setup will allow us to connect to our DocumentDB database.
Create the SSH Tunnel Connection
Now that we have the SSH Tunnel setup with an AWS EC2 instance. Let’s now jump into using that SSH Tunnel to make a connection to our newly created private DocumentDB database.
Open new terminal tab and connect to DocumentDB:
Now we can simply make a connection to 127.0.0.1:27017 and we will be connecting directly to our private DocumentDB database! 💥 💥
Some MongoDB things:
Since we did all this work let’s actually run some commands against our awesome new DocumentDB instance. ✨
Create Database and Collection:
Insert data:
View data:
Fantastic! We’ve done a lot. I hope that you’re now more prepared to go out and tackle other similar problems 😄.