Create High Availability Architecture by Provisioning CDN with Cloudfront in AWS CLI

To create the architecture using Cloudfront we have to follow these steps:-

  1. Create an instance with a web server configured attached with 1gb EBS (Elastic Block Storage) make our data persistent.

  2. Create S3 Bucket and adding static files to it.

  3. Static objects used in code such as pictures stored in S3.
  4. Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
  5. Finally place the Cloud Front URL on the webapp code for security and low latency.

Creating the instance:

Command:

aws ec2 run-instances --image-id ami-052c08d70def0ac62 --instance-type t2.micro --count 1 --security-group-ids sg-0abeb8b3e2dfac89e --key-name task_3

Screenshot 2021-03-20 223616.jpeg

Screenshot 2021-03-20 223711.jpeg

Now we are setting up webserver in our instance we launched:

Screenshot 2021-03-20 224940.jpeg

Starting and Checking the status of web-server:

Screenshot 2021-03-20 225634.jpeg

Now creating a new EBS-volume and attaching this volume to the instance:

command:

aws ec2 create-volume --availability-zone ap-south-1a --no-encrypted --size 1

Screenshot 2021-03-20 230653.jpeg

Now, attaching it to instance:

command:

aws ec2 attach-volume --volume-id vol-0dc7ef446eee499da --instance-id i-05527267dfe10957a --device /dev/sdf

Screenshot 2021-03-20 231514.jpeg

Screenshot 2021-03-20 232037.jpeg

Now making our EBS-volume ready to use by making Partition , formatting the partition and mounting this to /var/www/html

Making partition:

Screenshot 2021-03-20 233812.jpeg

Formatting the partition:

Screenshot 2021-03-20 234132.jpeg

Mounting this to /var/www/html:

Screenshot 2021-03-20 234324.jpeg

Creating S3 Bucket and adding static files to it:

command:

>aws s3api create-bucket --bucket arth-task-six --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1

Screenshot 2021-03-20 235050.jpeg

Screenshot 2021-03-20 235225.jpeg

Adding static file into the bucket:

command:

aws s3api put-object --bucket arth-task-six --acl private --key test1/solo-leveling.png --body "C:\Users\rithi\Downloads\solo-leveling.png"

Screenshot 2021-03-20 235826.jpeg

This will upload solo-leveling.png (photo) in the bucket in a directory named test-1

Screenshot 2021-03-21 000910.jpeg

Now using CloudFront Setting up Content Delivery Network and using the origin domain as S3 bucket:

command:

aws cloudfront create-distribution --origin-domain-name arth-task-six.s3.amazonaws.com --default-root-object  test1/solo-leveling.png

Screenshot 2021-03-21 001228.jpeg

Screenshot 2021-03-21 002054.jpeg

Finally placing the Cloud Front URL on the webapp code for security and low latency.

Screenshot 2021-03-21 012513.jpeg

Screenshot 2021-03-21 012411.jpeg

as the availability of s3 is more then that of EBS storage the architecture created above has high availability also by using Cloudfront which is fastest CDN we can access website with low latency.