A quick recipe to create and test an instance of EC2 on AWS, Part I

Rodrigo Ancavil
4 min readOct 11, 2019

--

This recipe is divided into two parts, Part I, It will show you how to create an instance of EC2 on Amazon Web Services, and Part II, we will develop a simple socket server (called socketServer) to test how we can deploy a server using a specific port.

First of all, I assume that you have an account on Amazon Web Services.

Enter and select service EC2 then go to launch instance option. In QuickStart and you have to choose one of the S.O. Available.

In this case, I have selected Ubuntu Server 18.04 LTS (HVM), SSD Volume Type (a Free for eligible), and push Select button.

Choose an instance type, I selected t2.micro and going to Review and Launch (Fast trackway).

It’ll be shown a resume with instance features.

If you are ready, press the Launch button.

You have to create a new key pair if you don’t have one yet. Put the Key pair name (name-of-your-key-pair). Put Key pair name (see below image).

And download Key Pair on your Local computer, push Download Key Pair button (it will be download a pem file with the pair name gave it).

Push the Launch Instances button. You’ll see Launch Status.

After that, you can back to the EC2 console, and you’ll see Resources the Instance, Key Pair and Volume recently created.

Alright. You have created an instance of EC2 in AWS.

Connecting with instance

Now, you have to configure your local computer to access the instance.

You have to change the privileges to pem file to allow the connection with EC2 instance.

$ chmod 400 <name-of-your-key-pair>.pem

You can connect using ssh.

$ ssh -i “<name-of-your-key-pair>.pem” ubuntu@<name-of-instance>.us-east-2.compute.amazonaws.com

Testing

We’ll create a little socket server with Python to test how would works the instance.

First, we have to configure the Security Group to allow the use of a specific port (9990 for our case). In the EC2 Dashboard go to the Security Group option, located on the Resources section.

You have to select the instance’s Security Group and go to Inbound option, and set up the new port (9990).

Push the Edit button, and Add Rule, then set up the new port.

Select Type: Custom TCP

Protocol: TCP

Port: 9990

Source: 0.0.0.0/0 (This allows that everyone can connect to the port).

Description: is optional

Save and go back to the ssh console.

$ ssh -i “<name-of-your-key-pair>.pem” ubuntu@<name-of-instance>.us-east-2.compute.amazonaws.com

Using your terminal, you’ll be able to access to ssh console.

Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0–1039-aws x86_64)* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Tue Jun 4 03:17:52 UTC 2019System load: 0.0 Processes: 87
Usage of /: 26.1% of 7.69GB Users logged in: 0
Memory usage: 14% IP address for eth0: 172.31.16.46
Swap usage: 0%
* Ubuntu’s Kubernetes 1.14 distributions can bypass Docker and use containerd
directly, see https://bit.ly/ubuntu-containerd or try it now with
snap install microk8s — classicGet cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
78 packages can be updated.
0 updates are security updates.
Last login: Tue Jun 4 01:44:33 2019 from 191.112.59.148
ubuntu@ip-172–31–16–4x:~$

I recommend you update the S.O. executing.

ubuntu@ip-172–31–16–4x:~$ sudo apt-get update

Now, we’ll need to check that we have python3 installed.

ubuntu@ip-172–31–16–4x:~$ python3Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

Now, we are sure that the instance is working with the O.S. updated and python3 installed. Now to test we are going to deploy a server socket. Go to the 2nd part.

--

--

Rodrigo Ancavil
Rodrigo Ancavil

Written by Rodrigo Ancavil

IT Architect and Software Engineer

No responses yet