Create High Availability Architecture With AWS CLI

Mihir Patel
5 min readMar 19, 2021

In this article you will see how to use AWS by the command line

👉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.

What is Cloud Front?🤔🤔

CloudFront is a CDN (Content Delivery Network) . It provides securely delivers data, videos, and APIs to customers globally with low latency, high transfer speeds . It retrieves data from Amazon S3 bucket and distributes it to multiple datacenter locations . It provides data with Network of data center it’s called Edge location . If you are in India you trying to access some data from website then data will provide to you from nearest location from you . So with low llatency , high speed access the data . By cloud front you can restrict some country to access the data .

What is Amazon S3?🤔🤔

Amazon S3 is Object storage . It provides scalability, data availability, security, and performance. It allows to upload, store, and download any type of files up to 5 TB in size. In this Blog you Will see hoe to use S3 in Website making .

Lets , start Practical …

  1. first Launch Ec2 Instance By ClI :
> aws ec2 run-instances — image-id ami-081bb417559035fe8 — instance-type t2.micro — security-group-ids sg-0ac9d9eddb7112a21 — key-name MYKEY

2 )Now we have to create on EBS volume of required size.

>aws ec2 create-volume — availability-zone ap-south-1a — size 1

We can see that our EBS volume(aws_cli_ebs) is created. Now we want to attach this volume to created instance.

3) Now attach volume with ec2 instance :

>aws ec2 attach-volume — device /dev/sdf — instance-id i-0c9a5b2a63562a902 — volume-id vol-012ee3948957fade1

Now you can see our volume attach with Ec2 instance .

4)Document Root(/var/www/html) made persistent by mounting on EBS Block Device :

Before mount be have completed partition and formating of vloume then mount on /var/www/html so Our data keep in ebs volume persistent and secure .

Partition:

Format:

mount :

> mount /dev/xvdf /var/www/html

Now our data will keep persistent in EBS volume .

5) Now install httpd server on Ec2 instances :

> yum install httpd>systemctl start httpd

I have already installed .

6) Now create the S3 buckket:

> aws s3api create-bucket — bucket climybucket — region ap-south-1 — create-bucket-configuration LocationConstraint=ap-south-1

Upload image in S3:

Use Object Url and Put In Our Website :

Use S3 Url in <img src=””>

Now see The website Which use S3 Bucket :

7) Now Use cloudFront

To access these Image We are now using S3 URL due to these we have to go travel through public Internet Network which may cause some kind of Delay or Latency or may be disconnection . Since Rather than Giving these Image URL we prefer AWS Cloud Front which is one kind of Content Delivery Network which provide one unique URL to S3 Object by which users from anywhere can access or see these content with less latency and fast connectivity via AWS Private CDN and Edge Location.

For creating coludfront from S3 :

>aws cloudfront create-distribution — origin-domain-name climybucket.s3.ap-south-1.amazonaws.com

Now from above image use domain name and put in Website so , We can access our data with low latency , high speed .

Now see again Website Which is use Cloud front :

By Cloudfront we can restrict country to use data .

Now Our webpage becomes faster in terms of speed…………

Thank you …

--

--