Setting Up and Connecting to EC2 Instance on AWS
Published: 2023-04-08 00:02:41

## Introduction
Virtual machine (VM) is one of the terminologies you will be conversant with when you use the cloud.
Virtual machine is a virtual representation or an emulation of a physical computer. You can think of a virtual machine as an operating system (OS) that you can work on without necessarily installing the OS on your physical laptop. For instance, a you can work on a windows operating system using Mac operating system without installing the windows OS on your MacBook. The virtual machine that runs on your physical computer is referred to as the **guest** while the physical computer running the virtual machine is referred to as the **host.**
Virtual machines can be set up on different cloud service providers. Amazon Web Service (AWS) offers her VM as Elastic Compute Cloud (EC2), Google provides her VMs as Google Compute Engine and Microsoft Azure provides her VMs as Azure VMs.

For the purpose of this article, we will be looking at how to set up a virtual machine (EC2 Instance) on Amazon Web Services (AWS).

Sign in to your AWS account [here](https://aws.amazon.com/console/) if you already have an account with AWS or you can signup with AWS is you don't have an account [here](https://aws.amazon.com/free/)
After you have signed in or signed up as the case maybe, the top left hand side you will see 9 dots services labelled services and a search bar in the search type EC2 or click on the 9 dots and scroll down to where you will see EC2. For the purpose of the article, I will be going with the former since it's faster as shown in the picture below:
![EC2 Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0jgoi7718ycyk0whxd8.png)
Note: A major thing to take note of when using AWS is to ensure your location is set right and close to your users or close to your location are to ensure a low [latency](https://aws.amazon.com/what-is/latency/#:~:text=Network%20latency%20is%20the%20delay,response%20times%20have%20low%20latency).
At your top right corner just before your user name, you will see your location with a drop down so you can set it to your preferred location. In this article I used my location N. Virginia as I am not setting to any target audience

Click on EC2 and this allows you to see the various instances that you have running. If you have no instance running, you will see running in parenthesis as zero.
###### Let's take a look at how to launch an EC2 Instance on AWS.
To create an instance you either click on the running instances or scroll down the page to where you will see launch instance. If you clicked on running instance, it will navigate you to another page. On the top right corner, you will see a launch instance box with a drop arrow click on the drop down arrow and select launch instance as that's what we are doing. There are other options in the drop down as launch instance from template and migrate server.
![Launching an EC2 Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ssjv64ki7jszs0nznnk.png)
If you scrolled down the page, you will a launch instance box with a drop down arrow as well, click on the drop down arrow and select launch instance
![Launching an EC2 Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d4wc857a1yj7ts6bunns.png)
After you have selected the launch instance, it will open a different dialogue section for you to name your instance, select the OS you want to use and the instance type and create a key pair value.
Name your EC2 instance as you wish
![Naming an EC2 Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4f83dsfsjhkbuf8dq6qm.png)
Scroll down and select the OS you want your VM to operate in. In this case, I will be using the Windows OS, you can use any OS you want to.
Then select the Amazon Machine Image (AMI) you want to use, in my case, I will leave the default Amazon Machine Image (AMI)
![Amazon Machine Image (AMI)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cr42oobh5ro0koteagvo.png)
After that, we will set the instance type. Inside the box to select the instance type, you will see the a link to compare instances. Click on it and select the instance type you want to use. I will just use a regular t2-nano instance type. You can scroll down and select any instance type of your choice.
![selecting instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6gtpp7rup529cq0foi9.png)
Next is setting up the Key pair. 
If you have already created a key pair before now, you click on the drop down arrow and select it or you can created a new key pair by clicking on created new key pair and this will navigate to where you create the key pair as shown in the image below. 
When you have named your key pair, click on create key pair so your key pair can be created.
![Naming key pair](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rci6fu590su3wnsw6idf.png)
Great, with all that done. The next step is the virtual network. For that I leave everything as default since AWS has set up the necessary virtual network. However, you can set up your virtual network as you wish. 
With that done, you are ready to launch your instance. Scroll down to the bottom of the page and click on launch instance.
![Instance launch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9w2t0qhxtnpkenudzie9.png)
After your instance is launched, you should see a prompt that your instance has is successfully launched.
The instance page will be loaded so you can see the number of instances you have launched so far on this page. In our case we can only see one instance as it the only instance we have launched.
![launch prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydip44db4x23ptmpzar6.png)
Well done on coming this far. Having launched our instances we will want to connect to it.
###### Connecting to the EC2 instance
Besides the launched instance there is a checkbox that allows to select the instance. Check the box and at the top corner you will a connect box, click on it to initiate the connection process
![Instance connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcmn30sg7cszrk8dowgn.png)
We want connect to RDP (Remote Desktop Protocol) to the instance.
When you click the connect box, the connection page will be loaded where you can select the connection type you want to use which in our case is the RDP. There are options to connect to the instance, the Session Manager, RDP Client (the one will be using) and the EC2 Serial Console. Navigate to the RDP Client by clicking on it; And we will use the default connection set up by AWS 
![RDP Client Connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b60ybbss2kgbyq7p8w4.png)
When you want to RDP to any instance, a password will be required. 
Scroll down a page a bit and you will see a Get Password dialogue box. Click on it so you can get the password which will allow you to RDP into the instance. Clicking on Get Password which downloads the password
![Get Password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5gewoxqqafqvsbwupff.png)
After downloading the password, you will be allowed to upload the password. Go ahead and upload the private key file from your downloads
![password upload](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6h2crdvohe8yordi2uw.png)
The uploaded password in this form is encrypted for security reasons but since we need it to RDP to the virtual machine, we will have to decrypt it so we can copy it, hence after uploading the password, decrypt it by clicking on the Decrypt Password dialogue box.
![Decrypt password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9ulaq41zkhc0pb1iwi2.png)
You will need a Remote Desktop file to use along with the virtual machine.  Just above the uploaded password, click and download the Remote Desktop file and also copy the password as illustrated in the picture below
![copying password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/477r7l8t52h9oxtp0va6.jpg) 
Now is time to connect to the virtual machine go ahead to connect to the virtual machine; the host (your physical computer) will require you to allow the guest(virtual computer). Allow the connection and your virtual machine is connected.
![Permission](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d9kxnviu7whwvnj3p6gc.jpg)
Know that your virtual machine is connected, you can do whatever it is you want to do.
Returning to the cloud, just above the virtual machine is the cancel symbol. Click on it, confirm you want to close the VM and the VM is closed
![closing VM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aagbnyqg92mxrmyyq2ae.png)
That was amazing, well done for coming this far.
It is always important to terminate resources that you are no longer using on the cloud so that you billing does not pill up.
Since we are done with why we were setting up the instance, we need to terminate the instance. Go to your instances and select the instance we have been working with and at the upper corner of the instance, click on drop down arrow besides the instance state and select terminate as that's the only option that will delete the resource. 
When the instance is successfully terminated, you should see a prompt that your instance was successfully terminated. 
![VM terminated](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khw0u4xlhwqppbbueduu.png)
You can also refresh the page to you will see that the instance was terminated
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ek28k8mrsv2obppe4vh.png)
Yeah....that simple, that's all there is to setting up and connecting to EC2 instance (a virtual machine). 
I hope you learnt a thing or two. 
Thank you for reading to the end, stay tune to this blog handle as I intend to blow your mind with more content.