Deploy your first app on cloud

Incase you need to understand the basics. Please refer to this post. You will need an Amazon Web Service Account. You don’t have to pay anything since we are sticking to the free tier. Following is an excerpt from the book Cloud Is a Piece of Cake.

Set up a Virtual Machine

What is a virtual machine?

Imagine a huge room. It can be sub divided into smaller compartments. Similarly, a computer of large capacity can be subdivided into smaller compartments or virtual machines. Each of these virtual machines feels like they have their own hardware. But, in reality, it doesn’t. It imitates dedicated hardware. Since it’s virtual, allocation and deallocation of resources are easy.

Note: In the top right of your AWS dashboard select the region which is closest to your location.

Create a Virtual Machine

AWS Dashboard

EC2 > Launch Instance

Select Instance OS

Here we select the OS of our virtual machine. We will be using Ubuntu. Select Ubuntu Server (Make sure it’s free-tier eligible as shown in the image).

Select Instance Type

Here we choose the configuration of our virtual machine. Select t2.micro or whichever is free-tier. Click Review and Launch.

Review and Launch

Here you can see security groups. Security groups allow you to restrict VM usage to specific IP. For now, it’s fine. Leave it that way. Click on launch to start the instance.

Create a new key pair

Key pair allows you to connect to your instance securely instead of a password.Download the key pair file and keep it safe. Once you have downloaded the key pair, you can click Launch Instances.

Instances

Now, wait till instance state is ‘running’. Then you are ready to go. Now we will use the public IP shown in the image to connect to our EC2 instance.

Connect to an EC2 Instance (Virtual Machine)

If you are using a Linux or a Mac OS

You will need to navigate to the folder containing the downloaded key pair on your terminal. I assume it’s in your Downloads folder. If you are not sure how to do this, please paste the file to your Downloads folder.

cd ~/Downloadschmod 400 myec2instance.pemssh -i myec2instance.pem ubuntu@54.183.227.71

If you are using a Windows OS

Download and install Cygwin. Paste the key file inside C:\cygwin\home\username; this

might be different in case you have changed your root directory. Once you paste it in the root directory, run the following commands.

chmod 400 myec2instance.pemssh -i myec2instance.pem ubuntu@54.183.227.71

Connect to an EC2 Instance

Installing Software Packages

What are Linux packages?

Linux packages are file archives containing all of the files needed for a particular application. All the Linux software comes in these packages. For now, we need two packages git and apache2

sudo apt-get install git -ysudo apt install apache2 -yApache Server

What is the apache server?

Apache is an open source web server that is used by most of the web servers around the world. A web server is similar to a receptionist who welcomes you and helps you with your requirement. Here a web server checks what the user has requested and serves him with web pages.

Currently, our EC2 instance disables any incoming traffic to our server. Our Apache server runs on port 80. We will need to add a security rule to allow connections on port 80. Login to AWS portal > EC2 Instance > Security Groups

Security Groups

Make sure launch wizard is selected then click on edit in the bottom.

Security Groups

Click on Add Rule. Select HTTP from the list > Save.

Edit Security Groups

Now go to your web browser. Navigate to http://YourEc2InstanceIP

Web Server Running

Let’s change the default page

cd /var/www/htmlsudo rm index.htmlsudo nano index.html

Inside index.html



This is amazing !





Hey congrats, You got the web server running. Let this take you places.



Enjoyed reading this? The other chapters in the book includes unix commands, bash scripting, making a news reader app, securing the app and scaling it. Learn more about the book here. Book is available for purchase on Amazon.

Deploy your first app on cloud was originally published in Piece of Cake Labs on Medium, where people are continuing the conversation by highlighting and responding to this story.

 •  0 comments  •  flag
Share on Twitter
Published on January 13, 2017 13:49
No comments have been added yet.