High Availability Architecture with AWS CLI

High Availability Architecture with AWS CLI

This is the task given in ARTH(School of technologies) training under Vimal Daga sir.

Task Description📄

🔰 Create High Availability Architecture with AWS CLI 🔰

🔅The architecture includes- 

- 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.

. Explanation

In the following article I have told how to use CLI and shown you by running different services through CLI

In this article I have talked about how to launch instance and some more things like creation of key, security group and EBS volume and attaching it with the instance using CLI.

Now before doing further things, i created some more power shell variables for future reference.

$image_path = "D:/arth_task6/vishal.jpg"
$key_location =  "D:/arth_task6/vish_task6_key.pem"

$PublicInstanceIP = aws ec2 describe-instances |  jq ".Requirements[2].Instances[].PublicIpAddress"          

Using this I am fetching public of the instance and storing in a variable PublicInstanceIP so that i can login.

->By following command i am installing httpd apache software. This command goes inside the instance login, install software and come out automatically

ssh -i $Key_location ec2-user@$PublicInstanceIP sudo yum install httpd -y
No alt text provided for this image
No alt text provided for this image

-> Creating partition

ssh -i $Key_location ec2-user@$PublicInstanceIP sudo fdisk  /dev/xvdh
  • fdisk is the main Linux command for partition related things
  • /dev/xvdh is the EBS separate attached volume which is partitioning
  • It takes inside the hard disk and there we have to do perform all the partition related steps
  • Like which type of partition you want to create primary or extend, size of partition, etc.
No alt text provided for this image
No alt text provided for this image


-> Format and mount the created partition.

ssh -i $Key_location ec2-user@$PublicInstanceIP "sudo mkfs.ext4  /dev/xvdh1; sudo mount  /dev/xvdh1  /var/www/html" 
  • Here I am running two command through one login.
sudo mkfs.ext4  /dev/xvdh1
  • Is to format. mkfs.ext4 is format type and /dev/xvdh1 is partition name.
sudo mount  /dev/xvdh1  /var/www/html
  • Here I am mounting the same partition with /var/www/html folder which is document root of Apache server.
No alt text provided for this image

->Command to create S3 bucket.

aws s3api create-bucket --bucket vishak123 --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1
  • Creating bucket with name vishak123
  • In the region Mumbai.
No alt text provided for this image

-> Command to upload data in S3 with Public Read-Write Permission

aws s3api put-object --acl public-read-write --bucket vishak123 --key $image_path --body $image_path
  • This command taking image path dynamically.
No alt text provided for this image
No alt text provided for this image

Now I stored domain name of S3 vishak123 bucket in a variable

  • $s3_domain = "vishak123.s3.ap-south-1.amazonaws.com"

-> Created Cloud Front distribution and stored its url in a variable

$cloudFront_url = aws cloudfront create-distribution --origin-domain-name $s3_domain --query Distribution.DomainName
No alt text provided for this image
No alt text provided for this image

-> After this i stored html content in a variable.

No alt text provided for this image

->Configured webserver by uploading the content first in root folder then by copying in /var/www/html folder

  • Before this I transferred html code in a file by following way
echo  htmlCodeUrl  >  Vish_url.html
  • Copied in root folder by remote login.
  • scp is the command to copy from one OS to other in Linux
scp -i $key_location -r  Vish_url.html ec2-user@$PublicInstanceIP:~
  • And copied in /var/www/html
ssh -i $Key_location ec2-user@$PublicInstanceIP  cp  Vish_url.html  /var/www/html/index.html
No alt text provided for this image

-> And finally started httpd service

ssh -i $Key_location ec2-user@$PublicInstanceIP  service  httpd start
No alt text provided for this image

-> See Simple site

No alt text provided for this image

I have done everything from cli. But it can be automate using python. There we have subprocess and OS modules which executes system command. Then it will happen in one click.

Thank You......

To view or add a comment, sign in

More articles by Vishal Yadav

  • Classification,Confusion Matrix and Cyber Security

    What is Classification In ML? .A classification model tries to draw some conclusion from the input values given for…

  • ARTH Task 7.1B

    🌀 7.1B: Elasticity Task 🔅Increase or Decrease the Size of Static Partition in Linux.

  • ARTH Task 7.1A

    Task Description 📄 🌀 7.1A: Elasticity Task 🔅Integrating LVM with Hadoop and providing Elasticity to DataNode Storage…

  • Working with CLI on AWS

    I am going to tell you how can you access AWS(Amazon Web Services) using CLI(Command Line Interface) I have used basic…

    1 Comment
  • Devopsal Task-5

    Task Overview Integrate Prometheus and Grafana and perform in following way: 1. Deploy them as pods on top of…

  • Ansible Task-1

    Task Overview Write an Ansible PlayBook that does the following operations in the managed nodes: 🔹 Configure Docker 🔹…

  • DevOpsAL Task-6 Continuous Integeration and Delivery with Groovy approach.

    This is the overview of task. Perform third task with the help of Jenkins coding file ( called as jenkinsfile approach…

  • HybridCloudTask-4

    This is the overview of task. 1.

  • CloudTask-3

    This is the task overview. Statement: We have to create a web portal for our company with all the security as much as…

    1 Comment
  • Aws-Eks Project

    In this project i have launched joomla on the top of amazon EKS(Elastic kubernetes Service) cluster. In this project i…

Others also viewed

Explore content categories