Akanksha Chhattri

Oct 31, 2020

5 min read

Creating Architecture using Cloud Front with AWS CLI

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.

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.

So lets begin this task. 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.

💥Lets launch the EC2 Instance using this

Command

aws ec2 run-instance — image-id ami-0e306788ff2473ccb — instance-type t2.micro — count 1 — subnet-id subnet-4d225201 — security-group-ids sg-0b661c0a3355410f1 — key-name cli_test

Lets check in webUI

💥Create EBS volume

Command:

aws ec2 create-volume — availability-zone ap-south-1b — volume-type gp2 — size 1

here we can see the new volume is created and it is available which means its is not attached to any instance

💥we gonna attach this newly created volume to an instance

Command:

aws ec2 attach-volume — device /dev/sdb — volume-id vol-0b4c2f27b905ca805 — instance-id i-0ff2ffd83ac0b7260

we an see in webUI that is attached

To user any raw hard disk or EBS volume we need to format it, for that we are going to follow 3 steps

  1. Format
  2. Mount it

STEP:1 To create partition

fdisk <disk name>

STEP:2 Format the newly created partition and command is

mkfs.ext4 <partition name>

STEP:3 Mount the newly created partition on /var/www/html

💥Configure apache webserver in this instance for that we need to follow 3 step fanda

  1. configure the file
  2. start the service

STEP:1 In our case we need to install httpd software. Command is -

yum install httpd

y is used to confirm the installment

we can check the software is successfully in completed using #httpd -version command.

STEP:2 The configuration folder of httpd is /var/www/html. This is the folder to put all the web pages.

STEP:3 To use the software services first we need to start the services. Command is -

systemctl start httpd.service

💥we are going to put our static data of website in S3 so here we are going to create bucket in s3 service of aws using cli and command is-

Command

aws s3api create-bucket — bucket <name of bucket> — region ap-south-1 — create-bucket-configuration LocationConstraint=ap-south-1

Let check the bucket in webUI

Upload image to S3 bucket.

Command :

aws s3 cp “<path of image>” s3://<name of bucket> — acl public-read-write

lets check in WebUI

💥Create web distribution link using cloud front service

Command :

aws cloudfront create-distribution — origin-domain-name <>— default-root-object <name of file>

let check in webUI

Put this cloud front link into web page

Here we finally get page whose code come from EBS volume, Static data like images store in S3 storage and the Cloud front link is used.

!!!Thank you !!!