AWS for Machine Learning — Part 3
A detailed explanation of using AWS EC2 services for free
After creating a free account on AWS and completing the signup process as shown in the previous article we end up with a screen like below.
Amazon EC2: Amazon Elastic Compute Cloud — This service lets you create your own virtual machines on which multiple services or programming languages or scripts can be run.
Let us now create a VM in EC2.
Step1: Click on EC2 under compute or search for EC2 in the search bar. After clicking on EC2 you will end up with a screen as below.
Step2: Now click on Instances(running) you will end up with a similar screen below. All the existing instance if you have already created will be present here else it will be empty as below.
Step3: Now click on launch instances now you are actually trying to create a cloud server. You will be presented with multiple options as below.
Choose an AMI: Here on the logo, it will show as a Free tier eligible for the free versions available. Now let us select Ubuntu Server(any version works)(Why ubuntu?? — I usually develop in ubuntu). Now click on select of Ubuntu server 20.04LTS with default 64bit(x86)
Step4: Now Select Instance Type: As highlighted in green in the below image t2.micro is the free version available Instance type usually refers to the capacity of the server getting created. Each type will have varied CPUs Performance etc. The more you are willy to pay the better servers will be available. Now click on review and launch(make sure you select free tire so that you will not be charged).
Step5: After clicking on review and launch you will be directly taken to Review as below. There are multiple steps in between where security groups are added Storage and multiple extra tags are also added we skip these for now. Since these are more related to security and large-scale storage. Now you can click on launch as below.
Step6: After clicking on launch you will be asked to create a new key pair:
A key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance. Amazon EC2 stores the public key, and you store the private key. You use the private key, instead of a password, to securely access your instances.
Select Create a new key pair on the first dropdown box and Enter the name of the project in the second box(key pair name). Now click on download key pair. A prem file will be downloaded. let us keep it for now. After downloading the Prem file we can now click on the launch instance as shown below. It will take few minutes to launch the server.
Step7. Now go back and click on the AWS logo and then select EC2 and then select Instances(running) as we did in step1. As you can see below an instance is created.
As you can see in the above image we can name the instance below where we can type the name and then click on it to save the name.
So now you have an Ec2 instance created and running as shown in the instance state column.
To connect to the server select the instance which is created and then click on Actions — >Connect as below.
Now run the following commands in the terminal:
- chmod 400 TestServer.pem -> in the same folder as the pem file which was downloaded previously to give permissions.
- ssh -i “TestServer.pem” ubuntu@ec2–13–234–122–162.ap-south-1.compute.amazonaws.com — > ssh connect command
The above two commands are shown on the screen as below.
Check out the terminal below for the commands
This is how to create an environment and connect to an instance in EC2.
Now you have a new machine where you can install python pull the code from git and play around just like how it is done on your PC.
Security Groups:
Now we have an instance, let us assume we need it to be accessed from everywhere. We need to create a security group and assign it to the instance.
In the left column select security groups under Network and Security as shown above.
In security-groups click on create security groups. then Enter the Name and Description. I have entered FullAccess as Name and description as below.
Now click on add rule and select
1. Type → All traffic
2. Source →Anywhere
In both Inbound Rules and Outbound Rules and then click on create security groups.
Now the security group full access is created as shown below image.
Now the newly created FullAccess security group needs to be linked with the EC2 instance TestServer1
Now on the left column click on Network Interfaces inside Network & security. Now for TestServer1 and right-click and then select Change Security Groups as below.
Search for security group FullAccess and select it, then click on the add security group. Then click on save, as shown below
Now go back to the Network Interfaces page and then refresh the page Now the column security groups for the instance consists of the name FullAccess as shown in the image below.
Now you are able to create an instance access it and change permission for the instance using security groups and run a project on the AWS EC2 instance for free.
Want to learn more check out the topics below.
More references:
- Artificial Intelligence real or is it just a hype of this decade??
- Artificial Intelligence: Definition, Types, Examples, Technologies
- Artificial Intelligence vs Machine Learning
- Why Machine learning for achieving Artificial Intelligence? “ The Need for Machine Learning”
- Machine Learning Types and Algorithms
- Linear Regression Part -1
- Linear Regression Part -2(example implementation)
- How to get AI-related jobs?
- So you want to build a chatbot from scratch?
- AWS for Machine Learning — Part 1
Make sure to follow me on medium, Linkedin, WhatsApp , Instagram to get more updates. And also if you liked this article make sure to give a clap and share it.
Follow me on Twitter.