Configuring Web Server and Designing High Availability CloudFront Distribution Using AWS CLI.

Adarsha Dinda
5 min readApr 8, 2021

Welcome you all to my article based on Creating High Availability Architecture with AWS CLI.

Have you ever thought that how data of big Website and websites are accessible from worldwide??Is any tool behind it??

Yes.. By using CloudFront service which is provided by Amazon AWS we can host our website or data worldwide. But what is CloudFront??

Let’s see….

Task Description:

⭕ Webserver configured on EC2 Instance

⭕Document Root(/var/www/html) made persistent by mounting on EBS Block Device.

⭕Static objects used in code such as pictures stored in S3

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

⭕Finally place the Cloud Front URL on the webapp code for security and low latency.

All the above steps must be performed using AWS CLI

🔅 First of all we have to launch one EC2 Instance in which we configure the Apache Webserver.

First of all you have to type aws help command this command shows all the service names. You have to know that instance running sub-service comes under ec2 service so type aws ec2 help here you find many options. Now you find the option run-instances in it. Now type aws ec2 run-instances help. Here you can see the multiple options so Finally you find this — image-id, — instance-type, — count, — security-group-ids, — subnet-id and — key-name options after giving the information about these options your command completed.

command :

#aws ec2 run-instances — image-id <value> — instance-type <value> — count 1 — subnet-id subnet <value> — security-group-ids <value> — key-name <value>

Let’s see on AWS CONSOLE our instance is launched or not ?

hurrah !!!! it’s sucessfully launched .

🔅 Now we create an EBS volume of 1 GB :

First of all you have to type aws help command this command shows all the service names. You have to know that volume creation comes under ec2 service so type aws ec2 help here you find many options. Now you find the option create-volume in it. Now type aws ec2 create-volume help. Finally you find this — availability-zone, — size and — volume-type option giving the information about these options your command completed.

command :

#aws ec2 create-volume — volume-type <value> — size <value> — availability-zone <value>

Let’s check on AWS CONSOLE our EBS volume is created or not ?

🔅Now we attach the above created 1 GB of EBS volume to the AWS EC2 Instance :

command : #aws ec2 attach-volume — instance-id <value> — volume-id <value> — device <value>

🔅 Firstly, we will install Apache httpd webserver on our Instance launched on AWS.

command : yum install httpd

🔅 To make Document root /var/www/html of apache web server

✔ First we have to create partition

command : fdisk /dev/xvdh

✔ Second we have to Formatting the partition

command : mkfs.ext4 /dev/xvdh1

✔ Last we have to Mount this partition with the the folder /var/www/html/

command : mount /dev/xvdh1 /var/www/html

✔ start httpd server

command : systemctl start httpd

🔅now we have to put the static content like images used in web code into the S3 Bucket for better availability . For these we have to create one S3 Bucket .

✔ To create S3 Bucket AWS CLI has Command as -

🔅 Now we can upload our objects / content inside S3 Bucket . To upload or copy any Local Static Content or files we have command as :

aws s3 cp {file_path} s3://{bucket_name}

Let’s check object is successfully uploaded or not ?

🔅Since our image is uploaded to bucket, now we create CloudFront Distribution for S3 bucket.

command : aws cloudfront create-distribution — origin-domain-name

Let’s check it’s distributed or not ?

We can see that CloudFront provides one Domain Name or unique URL to access the content with fast speed and low latency . Now we have to give these Cloud Front URL in our Code for the Image instead of S3 URL .Finally we can see our web page is now become more faster in terms of speed as one of the part of web page that is Image is coming from AWS Cloud Front CDN .

✔Our Cloudfront Distribution for S3 bucket is created, We will recieve all the information about distribution.

🔅Create a html file under /var/www/html/ folder

🔅now I am going to use web server using any browser

Link : ip_address/file_name

here my link is : 13.233.65.44/hello.html

Finally we can see our web page is now become more faster in terms of speed as one of the part of web page that is Image is coming from AWS Cloud Front CDN . The Second thing is that it is not possible for anyone to know right path of object which is stored in s3 .

Thanks for reading this!!

for any queries regarding this article ping me on LinkedIn.

(linkedin.com/in/adarsha-dinda-174b1b147)

--

--