Create High Availability Architecture with AWS CLI

Create High Availability Architecture with AWS CLI

Hi enthusiasts,

In this article we are going to configure webserver on AWS instance and create simple web app with high availability and security.

We should do following steps to setup AWS architecture

1.Webserver configuration on EC2 Instance

2.DocumentRoot(/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 Content Delivery Network using Cloud Front and using the origin domain as S3 bucket.

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

Webserver configuration on EC2

First, we create EC2 instance using CLI. Then we remote login to console using putty and install apache web server.

Creation of new EC2 instance

#creating ec2 instance 

aws ec2 run-instances --image-id ami-098f16afa9ef40be --instance-type t2.micro --count 1 --security-group-ids sg-08b23e40a7d598ffe --key-name keyhadoop --subnet-id subnet-19ec4746

No alt text provided for this image
No alt text provided for this image

Installing Apache webserver on AWS EC2 instance. yum is the command that is used to install any software in Redhat Linux. httpd is the software used to configure system as webserver.

yum install httpd



No alt text provided for this image

We successful installed the httpd software.

To start webservices we need to start webserver using systemctl command.

systemctl start httpd

To check the status of webserver we use following command

systemctl status httpd

No alt text provided for this image

We are done with first part step. Let's go to step 2

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

There are 2 folders provided by httpd.

1./var/www/html

2. /var/www/cgi-bin

For doing front end work like creating static application designs we use html folder and we mostly use html, css, java script...languages at front end development.

Now we need to create new EBS volume. Attach the volume to instance and mount root (/var/www/html) folder to EBS volume. In general, by mounting folder to new volume we can secure data/code. By chance, If the hard disk corrupted we may loose complete data. So it is always recommended to have data in another drive/hard disk.

Creation of new EBS volume

#create EBS volume with 1 GB

aws ec2 create-volume --availability-zone us-east-1a --size 1

No alt text provided for this image

We have successfully created EBS volume. We can check in AWS Web UI

No alt text provided for this image

Now we need to attach EBS volume to instance

#attach instance to EBS volume

aws ec2 attach-volume   --volume-id  vol-06deab5b1a182ff32 --instance-id i-08e94773cc38ef313 --device /dev/xvdf

No alt text provided for this image

We successfully attached EBS volume to instance

No alt text provided for this image

Now we need to mount root folder to EBS volume. To mount any folder to the device we need to do 3 steps

  1. create partition of device
  2. Format
  3. mount the folder to the device

We can check the volume attached to instance

fdisk -l

No alt text provided for this image

1.Creation of partition

fdisk /dev/xvdf

No alt text provided for this image

2. Format

mkfs.ext4 /dev/xvdf1

No alt text provided for this image

3.mount the folder to device

# command to mount

mount /dev/xvdf1 /var/www/html

# command to check 

df -h

No alt text provided for this image

Now let's move to step 3...

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

Now we have to create s3 bucket, upload a image/object in a bucket, make the object public and get the URL of the object. Then we need to check weather the web app is work or not. For that we need write html code using URL to display image.

Creation of S3 bucket

 Command to create s3 :-
#    

 aws s3api create-buckett --bucket mypic333  --region ap-south-1  --acl public-read --create-bucket-configuration LocationConstraint=ap-south-1 


No alt text provided for this image
No alt text provided for this image

Upload an object to the S3 bucket. So for that we have to mention the source path and the destination path. For source path we have to mention the location where the object is stored and for the destination write the bucket name .

# upload image to s3 bucket

aws s3 sync "C:\Users\puvvadasahitya\Desktop\allinone\wallpapers" s3:// --acl public-read

No alt text provided for this image

To make object public we should click on image name and then click on make public option so it can be viewed/access by everyone .

No alt text provided for this image

Now copy the URL and create a sample web app to check webserver is working or not

No alt text provided for this image
# go to the html folder
 
cd /var/www/html/
 
#check list of files
 
ls
 
#create file (in my case it is k.html)
 
vi k.html
 
#enter following html code to display image
 
<body bgcolot='aqua'>
sahitya
<img src='https://mypic333.s3.ap.south-1.amazonaws.com/1.jpg' height='200' width='200'
</body>

No alt text provided for this image

Now enter the URL in chrome following way:

https://<public ip of instance>/<name of html file>

No alt text provided for this image

Wow it's working. let's proceed to next step.

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

Before going to further task we need to know what it is necessity of cloud front ???

Terminology we need to be familiar with....

edge location= smallest data center

Low latency=less time delay

Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to the users. CloudFront delivers the content through a worldwide network of smallest data centers called edge locations. When a user requests content that serving with CloudFront, the user is routed to the edge location that provides the lowest latency , so that content is delivered with the best possible performance.

No alt text provided for this image

If the user in a particular zone accessed the url for the 1 st time it takes time as the content should copy from server to the user nearest edge center . After that user in that zone can get content with low latency as the content is copied to the edge center. In general, the content in edge location is stored in the cache memory so by default content will only available for 24 hours in the edge location.

Now we need to create the cloud front distribution for S3 bucket objects.

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


No alt text provided for this image
No alt text provided for this image

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

We use the domain name as url in html code

No alt text provided for this image

As the server distributed the object in all locations. Now client can easily access the services from the server by using server public IP with very low latency & high speed.

We came to the end of the article. Hope you found this useful. I am sure there is more to learn!

Puvvada Sahitya













要查看或添加评论,请登录

Sahitya Puvvada的更多文章

  • Industry Use Cases for Kubernetes / Openshift from RedHat Experts

    Industry Use Cases for Kubernetes / Openshift from RedHat Experts

    Hi enthusiasts, In this article, I'm gonna share my most recent experience on a webinar held by Linux World Informatics…

  • Ping Google but not pinging Facebook from same system

    Ping Google but not pinging Facebook from same system

    Hi Enthusiasts, In this article, we gonna create a Setup that can ping google but not able to ping Facebook from the…

  • Industry Use Case on Automation using Ansible

    Industry Use Case on Automation using Ansible

    Hello connections, I am glad to share my experience about Expert Practical Demo Session on Ansible. I am thankful to Mr.

    1 条评论
  • Amazing Ways Alibaba uses AI/ML

    Amazing Ways Alibaba uses AI/ML

    Ever feel wonder??? Don’t know name of product, tried with long text in search bar..

    1 条评论
  • Basics of AWS CLI

    Basics of AWS CLI

    Hi enthusiasts, This is quick guide for configuring and using AWS CLI AWS is one of the leading public cloud platforms.…

  • Start-ups using AWS

    Start-ups using AWS

    Hi enthusiasts, This article will acknowledge you about Tech-based start-ups benefitting from Amazon Web Services. Why…

社区洞察

其他会员也浏览了