Creating an AWS EC2 instance

February 28, 2019

This 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.

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.

AWS EC2 Console

Next we will want to Launch an Instance. Let’s select the Amazon Linux 2 AMI (HVM), SSD Volume Type.

Choose an AMI

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.

Choose an Instance Type

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! ✨

Create/Download a keypair

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!

View the running EC2 instance

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.

Add a Name tag

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.

  
$downloads: mv sshtunnel.pem ~/.ssh/
  

Next, we need to change the sshtunnel.pem file permissions.

  
$~: chmod 400 ~/.ssh/sshtunnel.pem
  

Now let’s SSH into the instance and verify we are all setup!

  
$~: ssh -i ~/.ssh/sshtunnel.pem ec2-user@private_ip
The authenticity of host '12.345.67.89 (12.345.67.89)' can't be established.
ECDSA key fingerprint is SHA256:zN5/1+w8kB/AFFFAz/jHhjSn/PFic131331444UU128.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '54.244.78.42' (ECDSA) to the list of known hosts.
   __|  __|_  )
   _|  (     /   Amazon Linux 2 AMI
  ___|\___|___|
https://aws.amazon.com/amazon-linux-2/
6 package(s) needed for security, out of 14 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-123-45-67-890 ~]$
  

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.

If you’re interested in learning how you can SSH into a private database on AWS. Then, keep following the series!

Serverless Handbook
Access free book

The dream team

At Serverless Guru, we're a collective of proactive solution finders. We prioritize genuineness, forward-thinking vision, and above all, we commit to diligently serving our members each and every day.

See open positions

Looking for skilled architects & developers?

Join businesses around the globe that trust our services. Let's start your serverless journey. Get in touch today!
Ryan Jones - Founder
Ryan Jones
Founder
Speak to a Guru
arrow
Edu Marcos - CTO
Edu Marcos
Chief Technology Officer
Speak to a Guru
arrow
Mason Toberny
Mason Toberny
Head of Enterprise Accounts
Speak to a Guru
arrow

Join the Community

Gather, share, and learn about AWS and serverless with enthusiasts worldwide in our open and free community.