High Availability Architecture with AWS CLI

High Availability Architecture with AWS CLI

Task-6 Description:-

Create High Availability Architecture with AWS CLI

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 Content Delivery Network using CloudFront and using the origin domain as S3 bucket.

5) Finally place the CloudFront URL on the webapp code for security and low latency.

Amazon Web Services (AWS)

  • AWS is a secure cloud services platform offering compute power, database storage, content delivery, networking, security & other functionalities to help business scale and grow.
  • AWS offers IAAS (Infrastructure As A Service) and PAAS (Platform As A Service).

Let's get started:

1. How to deal with EBS ?

(a) First of all Create IAM User to get access key and search key so to configure AWS CLI in command prompt and start one of the EC2 instance.

aws ec2 run-instances  --image-id ami-08e0ca9924195beba  --count 1  --instance-type t2.micro  --key-name myarthos1  --security-group-ids sg-0088112d467d8b387  --subnet-id subnet-d4235698
No alt text provided for this image

Command Line Interface (CLI)

aws ec2 create-tags --resources i-0cc23e7dde7592797 --tags Key=Name,Value=MyawsInstance

Giving tag to Instance

No alt text provided for this image

Graphical User Interface (GUI)

(b) Create one EBS (Elastic Block Storage) volume of size 1 GiB.

aws ec2 create-volume --availability-zone ap-south-1b --volume-type gp2  --size 1

No alt text provided for this image

Command Line Interface (CLI)

No alt text provided for this image

Graphical User Interface (GUI)

(c) Attach EBS volume with EC2 instance.

aws ec2 attach-volume --volume-id vol-053ab5168cd7afa98 --instance-id i-0cc23e7dde7592797 --device /dev/sdb
No alt text provided for this image

Command Line Interface (CLI)

No alt text provided for this image

Graphical User Interface (GUI)

We can see the /dev/sdb is the new EBS volume of size 1 GiB is attached with EC2 instance.

(d) Create one partition inside the hard disk (EBS).

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

(e) Now we have to format the created partition.But before you have to install httpd software.

yum install httpd -y
No alt text provided for this image
No alt text provided for this image

(f) Mount this partition with the folder /var/www/html (Document Root).

No alt text provided for this image

Through lsblk command we can see now our partition is mounted successfully.

2. How to Configure Web Server on AWS Instance?

(a) Start httpd (apache web server) services through systemctl start httpd after installation completed.

No alt text provided for this image

Using systemctl status httpd command we can the status of the services (active or inactive).

Webserver is Configured Successfully.

(c) Create a simple file in /var/www/html directory e.g. lw.html in my case.

No alt text provided for this image

Since we are configuring web server & web server can pick only web pages for services which are placed in /var/www/html directory (Document Root). That's why we are creating files in this directory or else we can copy from another folder to this directory.

(d) When we try to access web page using URL containing Public IP and filename then it will error because of the SElinux security of server provided by AWS.

No alt text provided for this image

Using setenforce 0 command we can remove the security to avoid error and can check using getenforce command is it is disabled or not.

No alt text provided for this image

Now if we access the web page then it is not showing any kind of error.

3. How to Create S3 Bucket & Upload data inside it ?

No alt text provided for this image

Creating S3 (Simple Storage Service) Bucket using CLI and my bucket name is task6-cli-bucket

aws s3api create-bucket --bucket task6-cli-bucket --region ap-south-1  --create-bucket-configuration LocationConstraint=ap-south-1
No alt text provided for this image

Command Line Interface (CLI)

Also we can verify through GUI either bucket is created or not.

No alt text provided for this image

Graphical User Interface (GUI)

Bucket is empty initially, so we have dump some data there. I have uploaded one .jpg file inside the bucket using below command. (Note: here udit is folder you have to put file in that folder).

aws s3 sync "C:\Users\ok\Downloads\udit" s3://task6-cli-bucket
No alt text provided for this image
No alt text provided for this image

Make sure that public access is given to the bucket and all the files inside it. Otherwise client will not be able to access the data. Using below command i am able to give permission to my file.

aws s3api put-object-acl --bucket task6-cli-bucket --key udit.jpg --acl public-read
No alt text provided for this image

Make files public

Now we can access the .jpg file stored inside the bucket through the URL provided by S3.

No alt text provided for this image

Also we put the URL in the lw.html file which is in /var/www/html folder and then client can access it using public IP and file name from the server.

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

4. How to Create CloudFront Distribution & Integrate with S3 and Web Server?

CloudFront is a service of amazon that speeds up distribution i.e. used for Content Delivery Network i.e. static and dynamic web content such as .html, .css, .js, image files like .jpg, .jpeg, .png, etc. to your users.

No alt text provided for this image

Let's go to create distribution,

aws cloudfront create-distribution --origin-domain-name task6-cli-bucket.s3.amazonaws.com  --default-root-object udit.jpg
No alt text provided for this image

Command Line Interface (CLI)

We can also verify using GUI.

No alt text provided for this image

Domain Name (CloudFront URL) - Used to access data from nearby Edge Locations with low latency and high speed of network.

No alt text provided for this image

So now we can access .jpg file using CloudFront URL.

No alt text provided for this image

Also we put the URL in the lw.html file which is in /var/www/html folder and then client can access it using public IP and file name from the server.

No alt text provided for this image

CloudFront also provides a statistical report in which we can see the Cache Statistics, Popular objects, Top Referres, Usage, Viewers from different Locations so that we get know about Cache Miss and Hit also and many other information. Below the brief data is provided for brief idea.

No alt text provided for this image

And thus, all the objectives of the task are successfully completed. That's all from my side. I hope you will like article and able to learn something.

Thanks to visit my article.

Keep Learning! ??

?

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

Udit Agarwal的更多文章

社区洞察

其他会员也浏览了