In this task we need to do the following:-

1. Webserver configure on ec2 instance-

This command will create the ec2 instance with the required security group that allow to use ssh for configuring the instance and http for using webserver.

Now, after creating the instance, we need to install the Apache web server httpd. for that, we will use putty from our physical device.

The commands that we use to install httpd is- yum install httpd.

Here, we need to run one more command to run the webserver- systemctl enable httpd.

2. Mount /var/www/html with the ebs block storage to make it persistent-

To attach the ebs instance, we use the command- aws ec2 attach-volume —device /dev/sdh —instance-id i-0f5fc22ce3e0cb60c —volume-id vol-07a0ae2fa47cac1d9.

To use the attached block storage, we need to perform three operations —

  1. create partition.
  2. format it.
  3. mount it with /var/www/html

For this operations, we will use putty. The command to do the first operation is fdisk /dev/sdh and follow the instructions to create 1 primary partition (with all the 1 gb size).

Now, to attach the driver to complete the first step. The command we use is udevadm settle.

After the first step, we need to format the drive to create a new Inode table as per our requirement. the command is mkfs.ext4 /dev/sdh.

Now, for the final step, we need to mount the folder to the block storage. for that, we use the command- mount /dev/sdh /var/www/html.

We successfully mounted /var/www/html with the ebs volume. By doing this, we secured every file inside /var/www/html in case of system failure.

3. Store the images used in the web pages in the s3 bucket-

To put the image inside the s3 bucket, we use the command-aws s3api put-object — bucket mdkneema4321 — key s3_demo_image_aws.png — body C:\Users\DELL\Desktop\s3_demo_image_aws.png

In the above command, The body contains the location of the file while the the key key option contains the name of the object which can be seen inside the bucket for the particular file.

we can also verify the upload by the command — aws s3 ls s3://mdkneema4321/

We get the following url of the object from the below screen —

4. Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.

Now, we have the intelligent url — d1yavsgezpg1dq.cloudfront.net

5. Placing cloudfront url into the trial.html file.

we simple replace the <img src=’d1yavsgezpg1dq.cloudfront.net’> in the file trial.html

Note: I did the make public option inside the s3 bucket, using the GUI. Without that, we cannot use the cloudfront url. all the buckets, ebs volume and instances are removed.