DEV Community

Cover image for How to create High Availability Architecture using S3 and CloudFront?
Nitesh Thapliyal for AWS Community Builders

Posted on

How to create High Availability Architecture using S3 and CloudFront?

What is High Availability?

A highly available architecture involves multiple components working together to ensure uninterrupted service during a specific period. This also includes the response time to users’ requests. Namely, available systems have to be not only online, but also responsive.

Implementing a cloud computing architecture that enables this is key to ensuring the continuous operation of critical applications and services. They stay online and responsive even when various component failures occur or when a system is under high stress.

Highly available systems include the capability to recover from unexpected events in the shortest time possible. By moving the processes to backup components, these systems minimize downtime or eliminate it. This usually requires constant maintenance, monitoring, and initial in-depth tests to confirm that there are no weak points.

Example:

If you want to deploy a website and want your website to be fast, secure and available all the time even in the time of some failure in the network then High Availabilty Architecture comes in play.

It is important to create High Availability Architecture to work efficiently without any delay due to failure.

In this Blog we will perform following activities:

  • We will Launch an instance using AWS CLI
  • We will configure Webserver
  • We will Create an EBS Volume
  • We will Attach EBS Volume
  • We will Create Partition
  • We will create S3 Bucket
  • We will Create Cloudfront Distribution

Prerequisites

  • You should have AWS account, you can create AWS free tier account.
  • Install AWS CLI in Windows,Mac or in Linux.
  • Configure AWS CLI with IAM user.
  • It is preferred that you are aware HTML basics and Linux

Step 1:

Launch an Instance using AWS CLI

  • First configure the AWS CLI in your terminal or window cmd, here I'm using window cmd.
  • To configure provide Access Key, Secret Key and region name.

Now to launch an Instance, we require:

  • Image-id
  • Instance-type
  • Count i.e how many instance we want to launch
  • subnet-id
  • Security-Group-id
  • Key-name

Syntax:

aws ec2 run-instances --image-id ami_ --instance-type _type_id --count no_of_instance --subnet-id -a57e77cd --security-group-ids group_id --key-name key_name

aws cli

output:

aws cli

Step 2:

Configure Webserver

  • To Configure Webserver we need to install httpd i.e Apache Webserver in instance that you have launched in Step 1

  • To install httpd use command: yum install httpd

  • After httpd installation, we need to check whether service is started or not.

  • To check the httpd service use command: systemctl status httpd

httpd

  • And to start the service use the command systemctl start httpd

httpd

Step 3:

Create an EBS Volume

To Create an EBS Volume we require:

  • Availability Zone name
  • Size of Volume that we want to create.

Syntax:

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

Here ap-south-1a is availability zone, you have to give availability zone name where you have launched instance and 1 is the size of volume i.e 1Gb, you can give desired size to your volume.

ebs

Step 4:

Attach EBS Volume to Instance

To attach the EBS Volume to an Instance we require:

  • Volume-id (The volume that we have created in step 3)
  • instance-id (The instance that we have launched in step 2)
  • device (Example: /dev/sdf)

Syntax:

aws ec2 attach-volume --volume-id (volume_id) --instance-id (instance_id) --device(ex: /dev/sdf)

attach_ebs

Step 5:

Create and Format a Partition

  • Now open the instance that you have launched in step 1

  • run the command fdisk /dev/xvdf to create partition.

  • After running this command press n to create new partition and then press p and then enter.

  • To save the partition press w.

partition

-Now we need to format the partition.

  • To format the partition use the command mkfs.ext4 device_name

format

Step 6:

  • Mount /var/www/html directory to partition
  • We need to mount /var/www/html directory to partition because we will create our html page in this directory and it will be safe in this partion even in the time of instance failure.
  • To mount the directory use the command mount /dev/xvdf /var/www/html
  • And to check it is mounted or not use command df -h

mount

  • Now create HTML page, go inside directorye🌟 /var/www/html in your linux instance.

  • Create a HTML file.

Syntax:

<!DOCTYPE html>
<html>
<head>
<style>
img {
  width: 100%;
}
</style>
</head>
<body>
<img src="html5.png"  width="128" height="128">
<img src="html5.png" width="128" height="128">
</body>
</html>
Enter fullscreen mode Exit fullscreen mode
  • Now add your own content to the syntax above and create your own html webPage.

Step 7:

Create S3 Bucket

To create S3 Bucket we require:

  • bucket name(you can give any name)
  • region name(region name should be same like your instance region)

Syntax:

aws s3api create-bucket --bucket --region --create-bucket-configuration LocationConstraint= region

location

Step8:

Upload images in S3 Bucket

The images that you will use while creating website or webpage, store that images in S3 bucket so that images in your website will open with less latency or delay.

  • Go to the AWS service in AWS WebUi
  • Select S3 service
  • Now select your bucket that you have created in step 7 upload images
  • Make the images that are uploaded public so that all can see your images.

bucket

  • Now copy the link of the images in the S3 Bucket and paste that link in your webpage.

Image link

Step 9:

Create Cloudfront Distribution

We create Cloudfront Distribution so that everyone in the world can access to our website with same speed like we access locally.

We will make Cloudfront Distribution of S3 bucket so that images will open without any delay when someone will access the website from other countries.

To create Cloudfront Distribution we require:

  • origin-domain-name(S3 Bucket domain)

Syntax:

aws cloudfront create-distribution — origin-domain-name

CF

Output:

cf out

  • Now open the webpage using the Ip address of instance and file name in your browser .

WebPage

By performing all steps you can deploy your website with High availability,secure your website and make your website manageable.

Hope you find this blog insightful, Do give it a like 🌟

Thank you!

Top comments (0)