High Availability Architecture with AWS Command Line Interface(CLI)
ARTH Task-6
Task Description
- 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.
- Install HTTPD over Redhat OS. The command for installing the OS goes as follows:
yum install httpd
After successful installation of the HTTPD, Start the httpd services and check the working status of the server. The command for the same goes as follows:
systemctl start httpd systemctl status httpd
Following is the output of all the above commands:
- Configure the AWS-CLI by using the command with the output attached as below:
aws configure
2. Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
The next step is to attach an EBS Volume to the /var/www/html folder to make the data persistent.We can use the below command to create an EBS Volume of 1GiB
aws ec2 create-volume --availability-zone --size --volume-type gp2
Now we can attach the above created EBS volume to the desired instance using the below command and the CLI and GUI outlook is as belows:
aws ec2 attach-volume --device sdb -- instance-id instance id --volume-id volume-id
In order to check if the volume is attached or not we can we can use the below command
fdisk -l
The output of the command is as follows:
Now we can use the following command to get inside the /dev/xvdb directory.The command is as follows with the desired output below:
fdisk /dev/xvdb
Now that we are in the desired directory we can create a new partition.We can press "n" to create a new partition and "p" for primary partition.The output is as below:
Now we have to format the partition using the below command
mkfs.ext4 /dev/xvdb1
The output of will be seen as follows:
Now we have to mount the partition to the /var/www/html folder and in order to check the attached disk we can use the below commands to which the output will be as follows:
mount /dev/xvdb1 /var/www/html df -h
3.Static objects used in code such as pictures stored in S3
Now we have to use the AWS CLI to create a S3 bucket the command for the same goes as follows:
aws s3 mb s3://bucketname --region
Now we can upload the desired data to the bucket and set the permissions to public
aws s3 cp (location) (name of object) s3://(bucketname)/imagename.png --acl public-read
4.Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
Now we have to create a distribution in cloud front to distribute the data to all Edge Locations of AWS by using the below command and the below is the output:
aws cloudfront create-distribution --origin-domain-name bucketname.s3.amazonaws.com
5.Finally place the Cloud Front URL on the webapp code for security and low latency.
The last step is to create a HTML code and specify the cloudfront url in the image tag.The HTML code goes as follow:
Now check the final results by using the following
http://IP/FileNamw.html
The final result are as follows