Amazon EC2 Launch Step by Step with static web page Hosting on Apache

Akash Deep
Analytics Vidhya
Published in
8 min readSep 5, 2020

--

Amazon EC2

In the series of Cloud computing we had already seen the basics of cloud computing along with the type and architecture. Also we had discussed about the vendor of cloud computing that are present in the market. This article is the continuation of the last article user cloud computing series. In this article we will try to understand all about EC2 instance and we will try to launch the virtual machine and will host a static web page on the machine.

Before going ahead, First will try to understand what is EC2. EC2 is a virtual machine provided by Amazon Web Services. EC2 stands for Elastic compute cloud. We will break the 3 words and try to understand the real meaning. First is Elastic, it means which means object which can be resize, i mean which can be compressed and stretched, Compute means computer and at last cloud means Internet, We had discussed about cloud in our last tutorial. If we will combine the meaning of 3 words then it means “Computer hosted on cloud which can be stretched or compressed i mean which is elastic”. Now this is clear EC2 is a virtual machine which is hosted on cloud and it is provided by Amazon. Many other vendors like Azure, GCP also has their own virtual machine. In this article we will keep our focus on Amazon EC2.

To deal with EC2 first we need AWS account. I hope the folks reading this article have a AWS account. If not, i suggest create AWS account, it is very simple process. Go to the https://aws.amazon.com/free web address and follow the steps mentioned there. AWS comes with free tier for 12 month, but there is a limitation of each and every services. For detail information on all the services which is their under free tier i suggest, go to the same website and check in detail. In this article we are dealing with EC2, so we will look in detail for the usage of EC2 under free tier. I am attaching a screenshot which will show the detailed usage of EC2 under free tier. Amazon provides 750 hrs of usage per month under free tier.

EC2 Free tier usage

After signing to AWS. click on login and provide the email and password to log in into the account. You will see the AWS Management Console. I suggest click on services which is present at the top left of the AWS management console.

AWS Management Console

After clicking on services the below screen will come, from services click on EC2 which we can see under compute section.

AWS Service list

After clicking on EC2, we will be entering in EC2 console and there will be lots of options. Don’t worry, as of now we will concentrate only on how to launch EC2 instance and how to get logged in inside our virtual computer, that is nothing but EC2. We will look all the flavors in detail in our further section.

EC2 Console

Under EC2 console we will have several options like Running Instance which sill show all the running instances under the AWS account. key pairs states that the number of key pairs present under the aws account. Key pair is needed when we will be logging in the virtual computer or EC2, and there are lots of option. we will discuss all the options in detail in our further articles. As i told earlier in this article our focus is mainly on EC2 instance. To launch instance click on launch instance present in the EC2 Console.

Launch Instance

After launch instance, we need to select the type of AMI, AMI is nothing but Amazon Machine Image. we can think AMI as the the ISO image for the operating system. Actually AMI is more than that of ISO, We will discuss in detail about AMI in next article. For this use case i suggest select Amazon Linux 2 AMI. This is nothing but Red hat linux

Amazon linux 2

After selecting AMI, Now we have to select the instance type. Instance type is the power of machine which we need to select. If you will see in console it will tell you clearly, what all the instance type is covered under the free tier, we will select t2.micro. There are lots of instance type, in real time we used to select this option as per our use cases. After selecting t2.micro click on next

Now we need to configure instance detail, as of now we will go with the default values of the instance detail. Now click on Next:Add storage

Instance detail

Under storage section we will not add any extra storage, If you want you can add extra storage by clicking on add storage button. As the storage is not part of this discussion we will skip this and we will go with the default one i mean will select only root storage. It will consist all the binary files and all the installation files of the machine. If you will compare this with your windows PC, In windows Laptop we have C drive which consists of all the binary values or all the installation files of your operating system, same in this case.

storage

Now we will add tags. Tags are very useful, as in real-time we will be dealing with lots of instances. Tags will identify the instance. so i will suggest give tag name as per your project case.

Adding tags

After adding tags now we have to configure the security group. Security group allows who all can login into your machine. By default port 22 is open. This is port is used for SSH into the virtual machine. We can open the ports under the security group options. In our use case we will open port 80, as apache listens on port 80. Anyway we will discuss the security groups in detail in our further article. we will try to understand Inbound, Outbound and many more.

Security group configuration

After configuring security groups click on Review and Launch. Click on Launch. Now we need to create a key-pair which we is required to SSH into the created EC2 instance. Click on create a new key pair and give name to key pair and most important click on download key pair. After clicking on download , .pem file will be downloaded in your download folder into your local machine. We need to convert this .pem file into .ppk file with the help of putty key gen.

Creating a key pair

Now click on Launch Instance. As soon as we had clicked on launch instance, it will take around 1–2 minutes and the instance will be up and running and this can be seen in the EC2 console.

EC2 Console

On the EC2 console we will have all the information related to the EC2 instance like public IP, Private IP, Security group Information, VPC information and many more. As of now we are interested in public IP Information. With the help of public IP and key value pair we will be entering into this machine

Ec2 console and public ip information

Now we need to focus on how we will get logged in into the running instance. For this we need putty. Putty is a tool which is used to get logged in into any of the virtual machine present on the cloud. Its very easy just download the putty from this web site https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html.

After downloading install it in your local machine. After installation, keygen also get installed by default into the system. Keygen is required for converting the .pem to .ppk file. Search keygen into your search bar. Click on load(it loads the .pem into the putty key gen) and click on save. The ppk file is saved in your machine and now we will use this ppk file to logging in to the launched instance. With the help of public ip and ppk we will logged in to the virtual machine.

Virtual machine

After getting into the machine we will update our machine using the command “sudo yum update”. Now we will install apache on the virtual machine with the command “sudo yum install httpd”. This command will install apache in your virtual machine

Now we will go to path “/var/www/html”. Under this path we will keep a static html page that needs to be display on the web browser. Below command is used to go the specified path

cd /var/www/html

We will create a simple web page by using below command

sudo nano h1.html

Below html code we will use to create a simple static web page. You are free to use any web page html or java script code that you need to display on the web page.

<html>
<head>
<title>Welcome, this is akash</title>
</head>
<body>
<h1>Congrats, apache is working on EC2</h1>
</body>
</html>

Congratulations, we had launched ec2 instance and also we had configured apache server on the vitual machine along with the simple web page hosting. If its not working for you i suggest use the command

sudo systemctl start httpd

Below web page is there that we can see over the browser.

Web browser

In the next article we will try to understand the components of EC2 instance in detail, and also we will see some other services in amazon web services. If you want to know more about cloud computing i suggest go through my 1st article in this series. The link for the article is below.

If you have any confusion regarding this article and creating AWS account, please comment below i will happy to respond. We will discuss more on AWS services in our next article under the series of cloud computing.

Stay Tuned

--

--