High Availability Architecture with AWS CLI
Udit Agarwal
Software Engineer | Python | GCP Cloud | Devops | Kubernetes | Grafana | AWS cloud | JAVA enthusiast | web developer | Docker | Rhel 8
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
Command Line Interface (CLI)
aws ec2 create-tags --resources i-0cc23e7dde7592797 --tags Key=Name,Value=MyawsInstance
Giving tag to Instance
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
Command Line Interface (CLI)
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
Command Line Interface (CLI)
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).
(e) Now we have to format the created partition.But before you have to install httpd software.
yum install httpd -y
(f) Mount this partition with the folder /var/www/html (Document Root).
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.
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.
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.
Using setenforce 0 command we can remove the security to avoid error and can check using getenforce command is it is disabled or not.
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 ?
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
Command Line Interface (CLI)
Also we can verify through GUI either bucket is created or not.
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
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
Make files public
Now we can access the .jpg file stored inside the bucket through the URL provided by S3.
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.
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.
Let's go to create distribution,
aws cloudfront create-distribution --origin-domain-name task6-cli-bucket.s3.amazonaws.com --default-root-object udit.jpg
Command Line Interface (CLI)
We can also verify using GUI.
Domain Name (CloudFront URL) - Used to access data from nearby Edge Locations with low latency and high speed of network.
So now we can access .jpg file using CloudFront URL.
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.
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.
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! ??
?