Creating High Availability Architecture with AWS CLI
The architecture includes-
- Creating and Configuring the Web Server
- Creating the EBS storage and Document Root(/var/www/html) mounting on it
- Storing the Static object in the S3
- Setting up the Content Delivery Network using CloudFront and using the origin domain as an S3 bucket.
- Finally, place the Cloud Front URL on the web app code for security and low latency.
The AMI used is Amazon Linux 2 AMI
For using the AWS CLI first we need to configure it, here is my article
Step 1: Creating and Configuring the Web Server
For installing the Apache Web Server
yum install httpd
The Apache Web Server works on port number 80 which is by default block by the AWS firewall for this we need to add the inbound Security rule
By adding the inbound rule the firewall will allow all the incoming traffic by port 80 on which the Apache Web Server is running
Step 2: Creating an EBS volume
aws ec2 create-volume --availability-zone zone_name --size 1 --volume-type gp2
Attaching the EBS volume to the instance
Aws attach-volume --volume-id vol-ID --instance-id i-ID --device /dev/xvdh
For Checking If the disk is attached or not we have a command
fdisk -l
Step 3: Formating and Mounting the disk Created
- Going to the partition by using
fdisk /dev/xvdh
- Creating the new partition
Step 4: Mounting the /var/www/html on the EBS volume
mount /dev/xvdh1 /var/www/html
Step 5: Creating the S3 bucket
http://task6anmol.s3.ap-south-1.amazonaws.com/grass.jpg
by the above link we can see the object uploaded in the bucket. Its syntax is like
<HTTP://Bucket_name.s3.region_name.amazonaws.com/object_name>
Step 6: Creating Cloud Front
aws cloudfront create-distribution --origin-domain-name S3_bucket_name
http://d1xuh9k9fa9yag.cloudfront.net/grass.jpg
http://task6anmol.s3.ap-south-1.amazonaws.com/grass.jpg
For checking the cloud front is working or not we can check it by opening the object by cloud front as <HTTP://domain_name.cloudfront.net/object_name>
Once the Cloud Front is ready now we can write the code