Integration with the AWS Services using CLI

In this article, I am going to show how we can 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 an S3 bucket.

- Finally, place the Cloud Front URL on the web app code for security and low latency.

NOTE:- I assume that you know about AWS CLI if not you can refer to my previous article “Managing AWS Cloud Services using AWS-CLI”

Lets Start…

  1. First, we need to create an EC2 instance and on the top of the instance, we can configure the Apache webserver.

Creating an EC2 instance needs image id, security group, and key for this you can refer to my previous article.

2 Configure our apache webserver on the EC2 instance using the below Commands.

yum install httpd -y

systemctl start httpd

systemctl enable httpd

Create a simple file in /var/www/html directory e.g. index.html in my case.

In this setup if our instance got crashed so all the data on its drive got deleted like the code which i wrote above so to overcome this issue we can mount this folder with extra hard disk and in AWS we use EBS to manage the same.

3. Create one EBS volume of size 1 GiB.

a. Attach EBS volume to your EC2 instance.

In the below picture, we can see /dev/xvdf is the new EBS volume of size 1 GiB is attached.

b. Create one partition of 1MiB inside the hard disk (EBS).

c. Now we have to format the created partition.

4. Create S3 Bucket & Upload data inside it

Also, we can verify through GUI either bucket is created or not.

Now I am going to upload the cd.png in the bucket in the CLI

But still, if some user from other location tries to access this webpage so it will face some latency issue due to the distance between origin and destination where the user uses the webpage, so to overcome this issue AWS has one service Cloud Front. In this whenever any user tried to use the webpage and content of the webpage like the images it will not cause any latency as it creates a copy of the data in the edge location of the Availability zone and next time any new user comes to the webpage they will get the data from that edge location only.

Let’s create one cloud front Distribution in order to upload the S3 image link.

5. Now we need to place the object URL of the bucket in the origin domain for setting up the CDN and to create the distribution.

From GUI you can verify it:

The CloudFront URL has been created so you need to place this in your HTML code.

But for loading URL they show some error that is forbidden error to solve this permission error by using the command.

6. Put the URL in the syntax http://ip/name of the file then enter

Now you can see the given output:


By using the CloudFront we have improved the security of webpages and decrease latency also.

Thank You!!!1



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store