Looking for Senior AWS Serverless Architects & Engineers?
Let's TalkThis article is part of a series 😃. With the end goal of connecting to a private database on AWS from our local computers. ✨
- 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
In this article we are going to talk about what a SSH Tunnel does and what it looks like using AWS EC2. By leveraging a SSH Tunnel we can connect to private databases on AWS from our local computers.
What is a SSH Tunnel?
“SSH tunneling is a method of transporting arbitrary networking data over an encrypted SSH connection. It can be used to add encryption to legacy applications. It can also be used to implement VPNs (Virtual Private Networks) and access intranet services across firewalls.” — Source: SSH
Why are we using a SSH Tunnel to connect to DocumentDB/RDS?
With a SSH Tunnel we can keep our database private and ensure that connections can only be made from inside the same VPC (Virtual Private Cloud).
What is Port Forwarding?
“Port Forwarding allows remote computers (for example, computers on the Internet) to connect to a specific computer or service within a private local-area network (LAN).” — Source: Wiki
On AWS, this means that we are connecting to the AWS EC2 instance with one terminal command.
Then, once that connection to our EC2 is established in the first terminal tab. We will run a second terminal command to make the connection to our private database.
The end result, we can now run database commands we are familiar with against our private database on AWS. 🎉
Let’s keep going
In the next article, we will jump into actually creating the AWS EC2 instance and setting up our .pem file for local connections.
Once we have our SSH Tunnel setup we will cover creating a DocumentDB instance and how to connect to DocumentDB locally. Extra benefit, this same process can be done to connect to RDS as well!