How to set up a website using AWS EC2 (Free tier)

Earl_Teye
5 min readFeb 27, 2022

What if I told you that you could set up a website for free? Well, this is a neat trick that I found as I started my journey in AWS Cloud Computing with Azubi Africa.

CONCEPTS

AWS stands for Amazon Web Service. They provide a number of cloud-based services with the core being Compute, Networking, and Storage. For the purpose of setting up a website, we would use the Compute services.

The compute service simply refers to having cloud-based computing resources available to you. An example being a Virtual Computer. The Amazon Elastic Compute Cloud (EC2) is simply a virtual computer. It has processing power that is freely resizable. It can be used for webservers, application servers and database servers. It falls into the AWS free tier offer for beginners

AWS Free tier is an offer available for anyone who registers an AWS account for the first time. It gives you free access to an EC2 (t2. micro), simple storage service (S3) and a few others for one year.

Any EC2 server is called an Instance. I would illustrate how to launch an Instance and install a webserver on it for launching a static webpage

Start

Create your AWS account and open your console. At the top left corner of your console, you can either click on services, find compute and then click on EC2 or simply search for EC2 in the search bar. This opens the EC2 console where you can launch an instance.

Launch your instance

  1. On the left pane, click on Instances.
  2. Click on Launch Instances.
AWS EC2 CONSOLE

Choose an Amazon Machine Image

An Amazon Machine Image(AMI) provides information required to launch an instance. This includes your Operating System, launch permissions and other information. We would choose the Amazon Linux 2 AMI which is at the top of the list and eligible for Free tier. Click Select.

Amazon Machine Image Selection

Choose an instance type.

This next setup allows you to choose an instance type that provides different combinations of CPU, memory, storage and networking capacity. We would use the t2.micro instance which should be selected by default and is eligible for free tier. Click Next: Configure Instance Details

Configuring Instance Details

This page is used to configure the instance to suit your requirements. This includes networking and monitoring settings. For the purpose of this exercise, we leave everything at its default settings

Scroll down till you get to Advanced Details. Expand the tab and you will find a field for User Data. When you launch an instance, you can pass user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. We are using the Amazon Linux, so we provide a shell script to run when the instance starts

Copy and paste the following codes into the User Data field

#!/bin/bash
yum -y install httpd
systemctl enable httpd
systemctl start httpd
echo '<html><h1>Hello, This Is Your Free Web Server!</h1></html>' > /var/www/html/index.html

This script would
- Install an Apache Webserver (httpd)
- Configure the webserver to automatically start on boot.
- Activate the Webserver
- Create a simple webpage

Click Next: Add Storage

Add Storage
Amazon EC2 stores data on a network-attached virtual disk called Elastic Block Store. You can have up to 30Gib disk volume for free tier. The default however is 8Gib and we would use this default for our instance. Click on Next: Add Tags

Elastic Block Storage selection

Adding Tags

A tag helps you categorize and recognize your AWS resources.
Click on Add Tags then configure the Key as Name and the Value as Web Server

Click Next: Configure Security Group

Security Groups
A security group acts as a virtual firewall that controls the traffic for one or more instances.
Configure the Security Group Name: Web Server Security Group and the Description: Security group for my web server.
For this exercise, we will not log into our instance using SSH. Removing SSH access will improve the security of our instance.
Change the SSH rule to HTTP

Launching your Instance.

Click on Review and Launch. This displays a Review page that lists all your configurations for the instance you are about to launch.
Click on Launch

A Select an existing key pair or create a new key pair window will appear.
Amazon EC2 uses public–key cryptography to encrypt and decrypt login information and since we don’t need to log into this instance for the exercise, we do not require a key pair.

Therefore Choose an existing key pair, and select the I acknowledge that I have access…

Now you can click on Launch Instances to launch your instance.

Accessing Your Website

Click View Instances
1. The instance will appear in a pending state, which means it is being launched. It will then change to running, which indicates that the instance has started booting. There will be a short time before you can access the instance.

2. Wait till the Status Check shows 2/2 checks passed

3. With your Web Server selected, click on the Description tab to review the information displayed. Copy your Public IPv4 address.

Next paste the IP address into a new tab with http://

Now you have your static webpage

This is how you install a web server on an EC2 Instance. The dynamics for an actual website would be different since you would need to log into your instance to implement changes to your webpage.

--

--