WEB SERVER USING EC2 INSTANCE AND AWS EBS VOLUME:

Pulkit Kaushik
5 min readJan 27, 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 , SERVER. HOSTNAME , PICTURE FROM EBS VOLUME

Steps:

(1) Navigate to Launch Instance in “Running Instances” page from EC2 Dashboard and 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 , one for root storage and the another as an external volume to store web app
related data is :
• 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 checked here on purpose.

(5) Provide appropriate Tags for the instance: It is an optional field.

(6) 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.

(7) Review your details provided for EC2 instance and select launch.

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

(9)In case of Amazon Linux 2 AMI image, you can directly connect to the instance from the Amazon management console.

(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

(11) 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

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

(13)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>”

(14) Create a HTML page using commands:

sudo ln -s /disk1 /var/www/html/disk1 && echo “<h1>Welcome to my 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:

--

--