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
In this article we are going to dive into building an AWS EC2 instance and connecting to that EC2 instance. We are going to jump straight into the AWS EC2 console versus go through creating an account and so on. If you would like to learn more about creating an AWS account with some helpful images, checkout our article. First Serverless Project and skip to the section called, Setup your AWS Account.
Creating an AWS EC2 instance
In the following sections we are going to cover a brief walk through of creating an AWS EC2 instance using the AWS Console. First things first, navigate to the AWS EC2 Console.
Next we will want to Launch an Instance. Let’s select the Amazon Linux 2 AMI (HVM), SSD Volume Type.
Let’s then select the Instance Type of t2.micro as it falls underneath the free tier and will allow us to create and run for free. Assuming, you don’t leave it running after the tutorial. Then hit Review and Launch.
We get prompted to select an existing key pair or create a new key pair. In our case we want to Create a new key pair. Let’s name the keypair, sshtunnel. Then hit Download Key Pair and Launch Instance! ✨
Once the EC2 instance has been created, you should see the Instance State of running. Awesome 😄, we now have a shiny new EC2 instance running!
To keep things organized, let’s also give this EC2 instance a name. I’m going to call mine, SSHTunnel. This change will show up in the AWS EC2 console and make it easier to parse what servers do what.
With the EC2 instance now running we need to do some local setup to allow us to connect to the EC2 instance. Most of this work revolves around modifying the sshtunnel.pem, which we will go through below.
Time to run some terminal commands 🎸 🎸
Assuming that you downloaded the sshtunnel.pem into your downloads directory. Let’s move the sshtunnel.pem file to our ~/.ssh directory.
Next, we need to change the sshtunnel.pem file permissions.
Now let’s SSH into the instance and verify we are all setup!
Success 🎉! You’ve launched an AWS EC2 instance and ssh’d into the instance. Nice work 😃
Cleanup:
Now let’s cleanup this instance so that we don’t get billed.
Perfect, you are now equipped the knowledge required to spin up a very basic EC2 instance. I would encourage you to go through the different screens in the AWS EC2 Console and play around with the various settings to help learn from experience.
Bonus ✨
This article was designed to solve a single problem (e.g. deploying an AWS EC2 instance), however this article is also part of a series on SSH Tunneling.
- Part 1: SSH Tunnel — AWS EC2
- Part 2: Create AWS EC2 instance
- Part 3: DocumentDB — Fully Managed MongoDB (Coming Soon)
If you’re interested in learning how you can SSH into a private database on AWS. Then, keep following the series!