Create High Availability Architecture with AWS CLI

Gaurav Singh Shekhawat
4 min readDec 7, 2020

--

Task DescriptionπŸ“„

πŸ”…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

Step 1-: Now we have to create a security group for our instance to create a security group we have to use the following command-:

aws ec2 create-security-group --group-name <GROUP_NAME_HERE> --description "Allow SSH"

Step 2-: Now we have to launch a Instance using the key pair and security group which we had created in the above steps.

Now we will launch an instance from the CLI by using the below command.

aws ec2 run-instances --image-id <AMI_ID_HERE> --count <NO._OF_INSTANCE_YOU_WANT_TO_LAUNCH> --instance-type t2.micro --key-name <KEY_PAIR> --security-group-ids <SECURITY_GROUP_ID_HERE>

Step 3-: Now we have to create a EBS volume in our instance-:

Step 4-: Now we have to attach a EBS volume in our instance-:

to attach EBS with instance we have to use the below command-:

aws ec2 attach-volume --instance-id i-0178b3e0d687cadb3 --volume-id vol-068747f4143a64254

Step 5-: Now we have to create a partition of EBS so that we can use it.

To Do Partition follow the below steps-:

  • mkfs.ext4 hard_disk_name
  • fdisk hard_disk_name β€” β€” -> will go inside your device.
  • p β€” β€” -> for details
  • n β€” β€” -> new partition
  • press enter (it will be first partition only)
  • press enter (it will be counting the space from initial sector)
  • w β€” β€” -> save thepartition and exit
  • mkfs.ext4 partitioned_hard_disk_name

Step 6-: Now we have to install Apache webserver in our instance, for that we will use yum command-:

yum install httpd -y

Step 7-: Now we have to mount our partitioned disk in /var/www/html.

Step 8-: now we have to add images in S3 bucket which we are going to use in our code. I have already a pre-created S3 bucket so i am using that only but you can also create a new bucket by using CLI with the below command-:

aws s3api create-bucket --bucket <bucket_name_here> --region <region_name_

Step 9 -: now we will create a cloud Front with the origin as above bucket so that we can get low-latency while accessing the images:-

to create distribution we use the below command-:

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

Now let’s check whether the cloudFront Url is working or not for that i am trying to see one of my image which is in S3 bucket via cloud Front Url-:

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” THANK YOU!!!! β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

--

--