HOSTING a WEB PAGE USING EC2 INSTANCE AND AWS EBS VOLUME:

Dipesh Kumar
5 min readJan 29, 2021

Agenda:

• Create an EC2 Linux instance with Amazon Linux 2 AMI

• Use default 8GB SSD EBS volume for root disk

• Attach a separate EBS volume of 1GB as a disk partition for storing other data

• Configure security policies to enable HTTP access

• Install & Configure httpd service

• Create a html page with following details- Server IP Address, Server Hostname, Timestamp, An image that is stored in the separate EBS volume

STEPS:

(1) Navigate to Launch Instance in “Running Instances” page from EC2 Dashboard and choose the appropriate AMI image. Choose the appropriate AMI image as required, in this case we choose Amazon Linux 2 AMI

(2) Choose instance type — for the purpose of POC, we can get ahead with the free tier:

(3) Select the network configuration, subnet and placement group for the EC2 instance

(4) Add EBS Storage (2nos.), one for root storage and the another as an external volume to store web app related data

• Root volume is created of size 8GiB — SSD [device name /dev/xvda] for OS installation

• Additional EBS volume of size 1GiB — SSD [device name /dev/sdb] for web app storage

Note: Delete on termination is not enabled for the additional EBS volume.

(5) Create Security group with required rules — you can also use existing relevant groups if available, and also store your new created group with metadata for future use and Choose appropriate key pair for the EC2 instance created use an existing key pair or we can also create a new one.

(6)After that Review and Launch.

(7) The instance will take sometime and will be up and running in new minutes and details can be seen on clicking the instance ID.

(8) Connecting to the EC2 instance using SSH

• In case of Amazon Linux 2 AMI image, you can directly connect to the instance from the Amazon management console

  • Alternatively, you can use the SSH key to connect to the instance from terminal or putty on your workstation (Recommended)

(9)List the attached EBS volumes — use command “lsblk” to see the attached EBS volumes. In this case we can see two EBS disk devices — xvda (8GiB for root) and xvdb (1 GiB)

(10)Create disk partition [1 time activity for EBS] — for the 1GiB EBS volume that is attached (/dev/xvdb)
• Use command “sudo fdisk /dev/xvdb” to start the fdisk util

Type command ’n’ to create a new partition
• Select the type of partition to be primary ‘p’
• Select default value for partition number
• First sector means the beginning memory location for the partition from the EBS volume (default
value is the beginning memory address of the disk)
• Last sector means the ending memory location for the partition from the EBS volume (default
value is the ending address of the disk)
• As we want to create a single partition using the entire disk of 1GiB, we can get ahead with the
default values.
• Now the disk partition of 1023MiB is created and is ready for mounting
• Enter command ‘w’ to save the partition

This can be viewed after completing the above step.

(10)Format the partition using command “sudo mke2fs -j /dev/xvdb”.

Mounting this 1GiB disk partition as “/disk1”
• Create a directory as “/disk1” and mount using the command ‘sudo mount /dev/xvdb /disk1’.
• Note: ‘/dev/xvdb’ is the EBS device name which is assigned while adding the storage

(11)Using command ‘df -h’, you can see that the disk of 1GiB is mounted as ‘/disk1’

EBS Volume mounted to Disk1

(12)Use this command to allow desired access- sudo chmod 777 /var && sudo chmod 777 /var/www && sudo chmod 777 /var/www/html

Install and configuring httpd package for webserver
• Command: sudo yum install httpd -y && sudo systemctl start httpd && sudo systemctl enable httpd.

Add an image to the /disk1 partition
• Command: sudo chown ec2-user /disk1 && cd /disk1 && sudo wget “/disk1/ADL-black-credo-copy-2.png” width=500>”

(13) Create a HTML page using commands:

sudo ln -s /disk1 /var/www/html/disk1 && echo “<h1>Welcome to Dipesh’s WebApp</h1>” >/var/www/html/index.html && echo “<img src=”/disk1/ADL-black-credo-copy-2.png” width=500>” >>/var/www/html/index.html && echo “<h4>Hostname: $(hostname -f)</h4>” >>/var/www/html/index.html && echo “<h4>IP Address: $(hostname -i)</h4>” >>/var/www/html/index.html

The web application is now created with the image stored in a separate EBS volume which can be accessed using public IP

(14)The hosted webpage can be found on the public IP of the instance from port 80 i.e. HTTP

--

--