In this task we need to do the following:-
1. Webserver configure on ec2 instance-
The first thing that we need to do is create an instance with security group that allows required inbound traffic (in this case all traffic for testing). the command to create is- aws ec2 run-instances — image-id ami-0947d2ba12ee1ff75 — instance-type t2.micro — count 1 — security-group-ids sg-0cd681b7ecf6e3ddb — key-name awsclass2020key — subnet-id subnet-e945dba4.
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 do the above, we first need to create the ebs volume of 1 gb in the same data center as the instance. The command to create the ebs is- aws ec2 create-volume — size 1 — Availability-zone
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 —
- create partition.
- format it.
- 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-
We first need to create the s3 bucket. The command to create the s3 bucket is- aws s3api create-bucket —bucket-name mdkneema4321 —region us-east-1
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.
To create the distribution for the cloudfront service, we use the command- aws cloudfront create-distribution — origin-domain-name mdkneema4321.s3.amazonaws.com — default-root-object s3_demo_image_aws.png
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