🔰 Create High Availability Architecture with AWS CLI 🔰

Siri Chandana
5 min readNov 6, 2020

--

🔅 The architecture includes-

  1. Webserver configured on EC2 Instance
  2. Document Root(/var/www/Html) made persistent by mounting on EBS Block Device.
  3. Static objects used in code such as pictures stored in S3
  4. Setting up the Content Delivery Network using CloudFront and using the origin domain as an S3 bucket.
  5. Finally, place the Cloud Front URL on the web app code for security and low latency.

Before going to task we need to know what is CloudFront 🤔

CloudFront : Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment. CloudFront is integrated with AWS — both physical locations that are directly connected to the AWS global infrastructure, as well as other AWS services. CloudFront works seamlessly with services including AWS Shield for DDoS mitigation, Amazon S3, Elastic Load Balancing or Amazon EC2 as origins for your applications, and Lambda@Edge to run custom code closer to customers’ users and to customize the user experience.

prerequisite:

  • Apache httpd

Now let’s start our Task 💻.

1)Webserver configured on EC2 Instance.

In the previous article (Task-3), I’ve shown how to launch an EC2 Instance through AWS CLI. Now I’m going to launch a web server on top of it.

First login to the the instance using SSH. Then we need to install the httpd software for Apache Webserver.

The command for installing httpd software is:

yum install httpd

Now, start the httpd service. You can also enable it to automatically start the server even after reboot. The command for starting httpd :

To start the httpd service :

systemctl start httpd

To enable the httpd service :

systemctl enable httpd

To check the status of httpd service

systemctl status httpd

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

The OS gets installed in the root hard disk i.e ‘/’ drive. The whole data we stored in system is comes to ‘/’. if our OS corrupts, all the data inside “/” drive will be lost. This is a big problem, since we lose all the data of our server. So solution for this is, attach an EBS volume to “/var/www/html” folder and make the server data persistent. For that use the following command to create an EBS volume of size 1GiB

aws ec2 create-volume --availability-zone us-eact-2c --size 1 --  volume-type gp2

Attach the above created EBS Volume to the Instance with the following command :

aws ec2 attach-volume --volume-id <id-of-volume> --instance-id <id_of_the_instance> --device /dev/sdb

Check if the volume is attached or not with the command :

fdisk -l

The volume is at the “/dev/xvdb”. Now, go inside the “/dev/xvdb” directory with the command :

fdisk /dev/xvdb

To create partitions follow below steps.

  • Enter “n” for creating a new partition.
  • Enter “p” for primary partition. Then, press Enter to accept the default parameters.
  • Enter “p” for checking the newly created partition.
  • Enter “w” to write the partitions.

Next format the partition the partition

To format the partition

mkfs.ext4 /dev/xvdb1

Now, mount the created partition inside “/var/www/html”.

mount /dev/xvdb1 /var/www/html

3.Static objects used in code such as pictures stored in s3.

Now create a s3 bucket from CLI .

aws s3 mb s3://siriu --region us-east-2

Next copy the file or image from your system to s3 bucket .

aws s3 cp siri.jpg s3://siriu/siri.jpg --acl public-read

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

Now create a distribution in CloudFront through CLI.

aws cloudfront create-distribution --origin-domain-name siriu.s3.amazonaws.com

5) Finally place the Cloud Front URL on the web app code for security and low latency.

Next go to /var/www/html to and write a html file .

cd /var/www/html

Here i am already create a simple html file using vi command

vi siri.html

in siri.html file i inserted the URL of siri image file.

Now, search the public ip address of instance along with html file name in any web browser.

http://PublicIP/HtmlFileName

Finally my webpage is look like this :

Finally our task is successfully completed😁.

Thank you for reading 📖.

Keep Learning ✌.

--

--

No responses yet