Create High Availability Architecture Using Cloud Front with AWS CLI
In this article, we will be configuring a web server of high availability architecture using Cloud Front.
1. What Is AWS CLI?
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
2.What is Amazon EC2?
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It offers the broadest and deepest compute platform with a choice of processor, storage, networking, operating system, and purchase model.
3. What is Amazon Cloud Front?
Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment
The main use of CloudFront is to create a local cache and when a client from the nearest location tries to access the content, then it will be used from the nearest edge location that is using Global Network set up by Amazon.
Edge locations are referred to the small-small data centers available at multiple locations and internally connected through some physical connectivity. They are not meant for actual storage, they only supposed to have cache data with a default TTL (Time to Live) time of 24 hrs.
4. High Availability 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 web app code for security and low latency.
LET’S START EXECUTING STEP BY STEP ….
STEP-1: Launch an instance from CLI -
- To Launch instance use the following command. Make sure to confirm the AMI id of a particular image of AWS.
aws ec2 run-instances --image-id ami-0915bcb5fa77e4892 --instance-type t2.micro --count 1 --subnet-id subnet-be09bfd8 --security-group-ids sg-08586f9c84fed2afb --key-name iAdarsh
STEP-2:Create an EBS volume of 1 GB.
- To create an EBS volume of 1GB we have to run the following Command but make sure you create the volume in availability zone same as that of instance.
aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone us-east-1b
STEP-3: Attach the above created EBS volume to your instance.
- Type the following command
Step 4: Configure the Web Server in the instance:
Here I am using putty to connect from the instance but you can do the same from command prompt using
ssh -i "iAdarsh.pem" [email protected]
After connecting to the instance run the following commands:
- sudo -i
- yum install httpd -y
You will see this type of output when httpd is installed successfully
3. Starting Httpd services
systemctl enable httpd --now
4. Checking the status
systemctl status httpd
5. Go to the Webserver Directory
cd /var/www/html
6. Create a Web Page Here and Put Your HTML code here,
vim index.html
This is my first HTML code …
And Now Open the IP of Device on a Web Browser You will find your WebPage
So we have successfully created the webserver and also started and enabled the httpd services.
Now let’s create a partition….
Step 5: Create, format, and mount our webserver to partition-
- To check the status of your disk, execute the following command in your command prompt:
[root@ip-172-31-6-158 html]# fdisk -l
[root@ip-172-31-6-158 html]# fdisk /dev/xvdm
- Create a primary partition as follows:
- Use the following command for giving driver to the partition:
[root@ip-172-31-6-158 ~]# partprobe
- Use the following command to format the partition:
[root@ip-172-31-6-158 ~]# mkfs.ext4 /dev/xvdm
- I used the following command to mount my partition on /var/www/html directory:
Now that we’ve created, formatted & successfully mounted our partition, let’s move on to create an S3 bucket
Step 6: Creating S3 bucket and uploading file into it-
- Execute this command to create an S3 bucket with public access, public access is important to let our webpage be displayed to everyone:
aws s3api create-bucket --bucket adarshnewbucket
- We can check the result using Amazon GUI as well:
Execute the following command According to your Device to upload the files of a folder into our bucket:
aws s3 sync "/Users/adarshkumar/Desktop/Photo/" s3://adarshnewbucket --acl public-read
As we can see, the file has been uploaded into our S3 bucket with read access to the public :
Step 7: Creating a distribution in CloudFront-
Let’s now create a distribution in CloudFront by using the following command:
aws cloudfront create-distribution --origin-domain-name adarshnewbucket.s3.amazon.com
My Final HTML Code. This file is created inside /var/www/html directory:
And here is the final output!!!
I hope you like the Blog and find it useful and all your queries and suggestions are highly accepted
?Keep sharing, keep learning?
Thank You !!! ????