Create High Availability Architecture with AWS CLI
Tags: beginners, aws, cloud
Published: 2023-01-17 03:34:55

Today's article is on S3 and CloudFront Architecture practical using AWS CLI.

## What is Amazon S3?

![S3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuzjk8xjhjrmb5i4kid1.png)

**Amazon Simple Storage Service** is storage for the Internet. It is designed to make web-scale computing easier for developers.

Amazon S3 has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.

**What is Amazon CloudFront?**

![CloudFront](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4lexf23lv3xch5cc3jx3.png)

**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. CloudFront is integrated with AWS — both physical locations that are directly connected to the AWS global infrastructure, as well as other AWS services.

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

![S3 and Cloudfront](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/719fk8ebyvftcgrckcc5.png)

For this follow the steps in my article: 

First we have to configure webserver on EC2 instance

![webserver](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdbny1ic2j4ta72npzfy.png)

The volume that we attached in my previous article on aws cli, we have to mount that volume to the document root (/var/www/html) to make it persistent.

You can find it here: https://dev.to/vrukshali26/lets-work-with-aws-cli-38po

For doing this firstly we have to create partition.

_All the below steps are done on Windows Command Prompt._

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7b098ijmy8k6gbkpzquv.png)

Here, you can see partition is created:

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j2gx7ekmslk8g1cqfprc.png)

Now, format the partition:

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7uy8bul80ogg4hr865ci.png)

Now, mount this partition to root document:

![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9gnlyf14r2qpomwt9qd.png)

Now, Static objects used in code such as pictures stored in S3.

For this first create a bucket

![ImageCLI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lxuv6hsxiqgzh4rpehr.png)

![ImageGUI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zy2650ighr1ch2ouia1g.png)

Now upload image in S3 bucket. Here, bucket name is “task-bucket-6”

![ImageCLI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gv9dhwds2ff3bhes0fqw.png)

![ImageGUI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itnode593p38mwxbpgpt.png)

Now make Bucket & object publicly accessible, Make bucket public:

![ImageBucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xr77nho2gwygq9s6jngv.png)

Make object public:

```
s3api put-object-acl --bucket task-bucket-6 --key 123.jpg --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers
```

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

![CDN](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hfc01qflirhh8yg5mwz.png)

![ImageGUI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vevyosi5do9g16h39kxx.png)

Now, lets create a small HTML code and put the URL in HTML code

![Imagecode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhef0xp72rxq6cq8ar75.png)

Now, lets see our web page

![Live](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tq90f8h29vfzcc92dqig.png)

You can read my previous blogs here: 
{% embed https://dev.to/vrukshali26 %}

Let's connect🚀: {% embed https://vrukshali.bio.link/ %}