What is compute?
Compute means basically calculation. And a system that does calculation or processing is we call as a computing machine or Computer.
Compute machines may be a small IoT device like Amazon Alexa or google home or maybe a smartphone or laptop or a blade server. We select the proper compute machine as per use case. Like anybody doesn’t bye a blade server for regular day to day tasks. Or you can’t use your laptop for serving high workload like web hosting. Every use case has a separate type of compute machine.
In the same way, whenever you want to do computation on the cloud, let’s say AWS you also have many choices. And the popular options are like
- EC2 for the regular virtual machines.
- ECS for Docker workloads
- EKS for Kubernetes workload.
- Elastic beanstalk for hosting a website without worrying about Operating System.
- AWS Lambda for executing a single program.
In this blog, I am going to talk explain EC2 i.e. elastic compute cloud service of AWS.
What is EC2?
EC2 or Elastic compute cloud an AWS service used to create regular virtual machines as we create on or desktop machines using VMware or VirtualBox or any other application.
Lets first understand what is actually a virtual machine.
The virtualization technology was invented for improving utilization of hardware. For using single hardware for installing multiple operating systems and using them at a time. Virtual machine are like over regular Windows or Linux systems but just difference is that they are using virtual hardware instead of physical hardware.
The architecture of a virtual machine is like
A hypervisor is a virtualization software like VMware or virtual box. If the production system is using virtualization technology then, in that case, they are not having an Operating system over hardware. In that case, the architecture will look like this.
This is called a Type 1 hypervisor where hypervisor providing basic functionality of the operating system itself.
AWS is using XEN and KVM hypervisor for EC2 service.
For creating a virtual machine what component you will need.
- Virtual CPU (VCPU)
- Virtual RAM
- Operating System Image.
All components are provided by AWS EC2 service.
How to Create an EC2 Instance on AWS?
Let’s create your first EC2 instance for a website hosting.
Login to your AWS console on https://aws.amazon.com/. If you don’t have an account then you can signup for a free account and for that you will need a credit card for verification. I am assuming that you have AWS account.
Follow the steps for launching the EC2 instance.
- Click on services and search for EC2
- Now you are on EC2 dashboard which will look like
- Click on Running instances or select Instances from the left side menu.
- Click on Launch Instance
- Now you are on AMI (Amazon Machine Images) page where you can select the operating system for your instance(virtual machine).
- We are going to use Linux o/s for web hosting.
- So select first AMI which isAmazon Linux 2 AMI (HVM), SSD Volume Type
- After Clicking on select you are on page where you can select hardware capacity for your virtual machine.
- Select t2.micro that is freely available on trial account.
- Select Next: Configure Instance Details.
- So now you are on page where you can configure Virtual machines like its network, ip and other things.
- For now, scroll down to the end of the page And click on Advance detail. You will get to see a small section of Userdata. Which works like post-installation. Here we are going to add a bash script for HTTP package installation and service activation. Paste the following script under user data.#!/bin/bashyum update -yyum install httpd -ycd /var/www/htmlecho “<h1> Welcome to my first web server </h1>” > index.htmlsystemctl start httpdsystemctl enable httpd
- Click on Next: Add Storage.
- By default, it takes 8Gb of storage for Linux machines and 30 Gb for windows machines.
- 8 Gb is enough for us so just click
- Next: Add Tags.
- Add the following tags
- Key – Name
- Value – WebVM
- Key – Role
- Value – Webserver
Tags are key-value pairs used for the identification of resources or grouping of resources with the unique keys.
- If it is done then just click on Next: Configure Security group.
- A security group is like a firewall where all inbound traffic is by default all denied. And we have to open the following port.
- ssh for remote access
- ICMP for ping test
- HTTP for web access.
- Give a name for the security group “WebSG”
- Click on Add rule and add these three rules
- ALL ICMP IPV4
- Make source anywhere for all rules
- Click on Review and Launch.
- And then Launch.
- You will get a popup like this from the drop-down menu select “ Create a new key pair” Provide a name for the key and click on Download Key and the Launch Instance.
- And congrats you successfully launch your first instance on AWS.
- Scroll down and click on View Instances.
- Wait for some time for changing Instance State to Available and status check to 2/2
- Copy the public IP from the description and paste to the new page of the browser you will get your webpage running.
- The next task is Connect to Linux instance.
Connect to Linux instance using Mac/Linux
- Open terminal
- Navigate to the directory where the key is downloaded.
- Change the permission to 400
Chmod 400 webvm.pemWhere webvm.pem is a key name.
- Use this command for remote access
- It will ask you for fingerprint first-time press yes
- And you are in.
For windows users, it is a little bit tricky.
Because popular application putty maybe you are familiar with does not support .pem key format.
So the first task will be converted .pem key to .ppm key.
Follow the steps.
- Download putty.
- Open Putty-gen
- Click on the file and load private key
Change the file type to all files from the right side bottom corner.
Select URL and click on Open.
- Click on Save Private key.
- Click Yes for saving the file without a passphrase.
- And close putty gen and open putty.
- On the left side under connection select + sign of SSH.
- And then select auth
- Click on Browse and select the key.
- Again click on session from the left side menu
- Enter the IP address and open the session.