
Hi folks!
This is a short article on building a web server using EC2 instance and EBS volume. We will be following the steps mentioned below:
- 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 1GiB and mount it to EC2 instance.
- Add some pictures to EBS volume(second volume).
- Install & Configure httpd service and create a html page with following details: Your name, Host name, IP address and the image stored in the EBS volume.
Steps:
- Sign in into your AWS management console and selecting EC2 services navigate to resources. Select running instances.

2. Click on Launch Instances.

3. Select the appropriate AMI image as required, in this case we choose Amazon Linux 2 AMI.

4. Select instance type — t2.micro.

5. Configure the instance details, here we can skip this.

6. Now, add another EBS Storage of 1GB where can store the images
- 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 on purpose to store important data even after the instance is terminated.

7. Add Tags: By tags you can specify the business environment or environment.

8. You can Create Security Group with rules. Security Groups are like virtual firewall in front of the EC2 instance. You can select the type of traffic you want in your EC2 instance as well the type of traffic you want outfrom EC2 instance.

9. Create an appropriate key pair if we do not have one.

10. Wait until your instance is up and running.

11. Click on the instance to view the public IP of the launched EC2 instance.

12. Now, you need to connect the EC2 instance using SSH:
- In this article Amazon Linux 2 AMI image was used so you can directly connect to the instance using EC2 instance connect.
- Alternatively, you can connect to the instance via SSH Client using .pem file and key pair.

13. To get the list of attached EBS volumes — use command “lsblk”.
- In this case you can see two EBS disk devices — xvda(8 GiB for root) and xvdb(1 GiB).

- Alternatively, you can use command “sudo fdisk -l” to view the attached disks.

14. Create disk partition — for the 1GiB EBS volume that is attached(/dev/xvdb).
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).
- We only need to create a single partition using the entire disk of 1GiB, so we use the default values.
- Now the disk partition of 1023 MiB is created and is ready for mounting.

- Enter command ‘w’ to save the partition.

- Format the partition using command:
sudo mke2fs -j /dev/xvddb
15. Mounting this 1GiB disk partition as “/disk1”.
- Create a directory as “/disk1” and mount using the command
sudo mount /dev/xvdb /disk1
- Now, using command ‘df -h’, you can see that the disk of 1GiB is mounted as ‘/disk1.

16. For Webserver, install and configure the httpd package.
sudo yum install httpd -y && sudo systemctl start httpd && sudo systemctl enable httpd

17. Add the image to the second storage — /disk1 partition.
sudo chown ec2-user /disk1 && cd /disk1 && sudo wget https://aptusdatalabs.com/wpcontent/uploads/2020/10/ADL-black-credo-copy-2.png
18. Create a HTML page.
sudo ln -s /disk1 /var/www/html/disk1 && echo “<h1> your name<h1>”> /var/www/html/index.html && echo”<h4>Hostname: $(hostname -f)</h4>”>> /var/www/html/index.html && echo”<h4>IP: $(hostname -i)</h4>”>> /var/www/html/index.html && echo “img src=”/disk1/ADL-black-credo-copy-2.png” width=500>”>> /var/www/html/index.html

19. The web application is now created and the image is stored in the second EBS volume. Navigate to the panel containing details of your EC2 instance and click on Public IPv4 DNS to access your website.
