A quick recipe to create and test an instance of EC2 on AWS, Part II
Following the recipe to create and test an instance of EC2 (see part I here), once we had created an EC2 instance, we are going to develop a practical example.
We have to connect to our EC2 instance from your local machine.
$ ssh -i “<name-of-your-key-pair>.pem” ubuntu@<name-of-instance>.us-east-2.compute.amazonaws.com
Now, we are going to deploy a python socket server. We have to connect to our instance.
Once, you are connected, you have to clone the project socketServer from Github.
ubuntu@ip-172–31–16–4x:~$ git clone https://github.com/rancavil/socketServer.git
Cloning into 'socketServer'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
Note: Socket server is a simple server that receives a message from a client, and sends back a response.
Ready?. To execute the server you have to do:
ubuntu@ip-172–31–16–4x:~$ cd socketServer
ubuntu@ip-172–31–16–4x:~/socketServer$ ./server.py
DEBUG:__main__:Server started 2019-09-27 03:44:37.602509
The server is working!!!
Before you test the server, you have to ensure that the security group has enabled the port 9990.
Ready to test.
You could clone the serverSocket project in your local machine and execute:
$ cd socketServer
$ ./client.py ubuntu@<name-of-instance>.us-east-2.compute.amazonaws.com
Enter message :
You can enter any message, we will use the classic Hello.
Enter message : Hello
The server will respond.
INFO:__main__:You will send <<Hello>> to server
INFO:__main__:Server side says 2019-10-27 04:10:26.160460 Message Received <<Hello>> from 191.11x.13.171
At the server-side we will see the following messages:
ubuntu@ip-172–31–16–4x:~/socketServer$ ./server.py
DEBUG:__main__:Server started 2019–10–27 04:09:37.401182
DEBUG:__main__:2019–10–27 04:09:40.457285 Received data from 191.11x.13.171
DEBUG:__main__:2019–10–27 04:09:40.459457 Created process 1766
DEBUG:__main__:2019–10–27 04:09:42.507894 Message Received <<Hello>> from 191.11x.13.171
DEBUG:__main__:2019–10–27 04:10:24.356126 Received data from 191.11x.13.171
DEBUG:__main__:2019–10–27 04:10:24.357009 Created process 1767
DEBUG:__main__:2019–10–27 04:10:26.159615 Message Received <<Hello>> from 191.11x.13.171
To stop the server, you just have to press CRTL-C and it’s all.
^CDEBUG:__main__:Server stopped
With these recipes, my aim is to share how to get started and learn to use AWS technologies. Enjoy.