Hey Folks!!

Isn’t it cloudy today? Yeah! Let’s match-up with the weather and exercise some Cloud practices.

In today’s blog, we’ll learn how to host a static website through EC2 instance on Amazon AWS. Let’s go through the tasks we’ll be implementing now-

  1. Launching an EC2 instance through the AWS console.
  2. Connecting to your Linux instance.
  3. Installing a Web Server on your EC2 instance.
  4. Adding a static HTML file & hosting it on the EC2 instance.
a) Launching an EC2 instance

Sign in to the AWS console.Traverse to EC2 dashboard and click “Launch Instance”.

1. Choose AMI

In this step, we’ll choose the operating system for our “Virtual Laptop” and the basic set of software that will come preinstalled. Choose a Free-tier eligible Linux option (Amazon Linux AMI, SSD Volume Type) and click “Select”.

2. Choose Instance Type

Let’s choose how powerful the “virtual laptop” will be — things like the number of CPUs, amount of memory, type of hard disk/storage, and network speed.

Choose the option marked as free tier eligible (General Purpose — t2.micro)— it will be one of the smallest, least powerful options. Click next to configure instance details.

3. Configure Instance

In this step, we’ll accept all of the default options. Check out the options to dig in more. Click next to add storage.

4. Add Storage

Next up, we will choose the hard drive(s) for your “Virtual Laptop”, and how fast it will perform. By default, a hard drive is already attached (root drive which boots the operating system). You can change the settings and add additional hard drives.

We will accept the default options and move to the next step. Click next to add tags.

5. Add Tags

Let’s add “tags” to manage and administer AWS resources. We don’t have a need for this, but add one for the experience. Click Add Tag— enter “name” for the key and “WebServer” for the value.

Click Next to Configure the Security Group.

6. Configure Security Group

Moving further, we will choose the type of traffic our “virtual laptop” will allow from the outside. We need to allow two types of traffic — SSH (to log in) and HTTP (to view our webpage through the browser). Select “Create a new security group”. Provide name & description as per your choice. Keep the SSH rule that is already listed.

Click “add rule”. Select HTTP for the type and keep everything else as it is.

Click review and launch.

7. Review

Ignore the security warning and click launch.

Note: A pop-up window will ask you to select or create a key pair. A key pair is needed to securely log in (SSH) to our new EC2 instance.

  • Select ‘Create a new key pair’
  • Give a name to the Key as per your choice
  • Click Download Key Pair
  • Click Launch Instances
  • Click View Instance to navigate back to the EC2 dashboard

As mentioned, we’ll use Private Key to access EC2 Instance via SSH Login.

Congrats!! Task-1 is accomplished. EC2 Instance is launched. 🙂

b) Connecting to EC2 Linux Instance

For connecting to your Linux instance make sure that it’s ready.

STEP 1: Install PuTTY and PuTTYGen to your PC

You can download PuTTY from given link : putty

Choose the MSI file according to your PC configuration.(32/64 bit)

STEP 2: Convert the Private key using PuttyGen

PuTTY does not natively support the private key format for SSH keys. The private key needs to be converted from .pem file to .ppk file with the help of PuTTYgen. For converting:

1. Open PuTTYgen.

2. Under Type of key to generate, choose RSA.

3. Choose Load. By default, PuTTYgen displays only files with the extension .ppk. To locate your .pem file, choose the option to display files of all types.

4. Select your .pem file for the key pair that you specified when you launched your instance and choose Open. PuTTYgen displays a notice that the .pem file was successfully imported. Choose OK.

5. To save the key in the format that PuTTY can use, choose Save private key. PuTTYgen displays a warning about saving the key without a passphrase. Choose Yes.

6. Specify the same name for the key that you used for the key pair and choose Save. PuTTY automatically adds the .ppk file extension.

7. Your private key is now in the correct format for use with PuTTY. You can now connect to your instance using PuTTY’s SSH client.

STEP 3: Connecting to your Linux Instance using SSH

1. Start PuTTY

2. In the Category pane, choose Session and complete the following fields:

  • To connect using your instance’s public DNS name, enter my-instance-user-name@my-instance-public-dns-name. user-name for Linux instance is ec2-user.
  • Ensure that the port value is 22.
  • Under Connection Type, select SSH.

3. In the Category pane, expand Connection-> SSH, and then choose Auth.

4. Choose Browse and select the .ppk file that you generated for your key pair and choose Open.

5. If this is the first time you have connected to this instance, PuTTY displays a security alert dialog box that asks whether you trust the host to which you are connecting. Choose Yes. A window opens and you are connected to your instance.

Voila!! We are connected to our Linux Instance. :))

c) Installing a WebServer on your Instance

i) Elevate your privileges and become the root user with the following command.

sudo su

ii) Update all of the packages on the instance with the following command.

yum update –y

iii) Install an Apache Web Server.

yum install httpd –y

iv) Start the web server.

service httpd start

v) Configure the web server to restart if it stops.

chkconfig httpd on

Yeah!! We came so far. WebServer is installed.

d) Add a Static HTML file to be hosted

1.Navigate to the directory.

cd /var/www/html

2. Manually create an index.html file in this directory.

nano index.html

3. Add your html code. We used below code:

	<title>Data Stats</title>
	<h1><i><font color="brown">WELCOME</font></i></h1>
	Voila!! Our Web Page is deployed on EC2.
	Stay tuned for more updates.

4. Save the file using Ctrl+O and exit the nano by pressing Ctrl+X.

Navigate back to the EC2 dashboard in the AWS console and copy the Public DNS(IPV4) or Public IP of your instance into your clipboard. Paste that address into your browser. If all went well, you will see the web page that you just created!

Hola 🙂 Our Web Page is successfully deployed on EC2 Instance.

Try out this exercise and let us know how you feel after hosting your WebPage. Comment down for any issues/suggestions.

Stay tuned for more such use-cases!!

– Rishita Anand Sachdeva


Leave a Reply

Your email address will not be published. Required fields are marked *

Insert math as
Additional settings
Formula color
Text color
Type math using LaTeX
Nothing to preview