How to Create High Availability Architecture with AWS CLI?
- Web Server 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 a Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
- Finally place the CloudFront URL on the webapp code for security and low latency.
For creating this High Availability Architecture with AWS CLI, you need to know some basic stuff like what is cli, how to create an ec2 instance and EBS volume. You can go through the below mentioned blog to understand those basic concepts and their workings.
AWS Command Line Interface|How to launch EC2 Instances & attach additional EBS Volume
What is a web server?
A web server is server software, or hardware dedicated to running this software, that can satisfy client requests on the World Wide Web. A web server can, in general, contain one or more websites. A web server processes incoming network requests over HTTP and several other related protocols.
The primary function of a web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP). Pages delivered are most frequently HTML documents, which may include images, style sheets and scripts in addition to the text content.
How to configure the web server in an EC2 instance?
Launch an EC2 instance in the process mentioned in the prerequisite blog and follow the below steps.
Install HTTPD using the following command:
# yum install httpd
After installing and configuring the apache web sever, start the services using the following command:
# systemctl start httpd
After installing the above package, Go to the “/var/www/html” folder and create file with extension “.html” and start writing the html script for your website.
The folder in which we have created our file to write the html script is in the root folder of the operating system. Keeping the file in the Root folder is reliable because as soon as the OS corrupts all the content in the Root folder gets deleted. So we can keep the content in “/var/www/html” a separate storage.
Here we will use “AWS Elastic block storage” to store our content “/var/www/html” so that our file will not get lost even if the OS corrupts.
To create an EBS volume and attach it to the EC2 instance you can refer to the above blog in the prerequisite section.
Every time we create a new storage we have to follow the following three steps:
- Create a partition.
- Format the above the created partition.
- Mount the formatted partition.
Command to create the partition:
cmd# fdisk <storage name>
Command to Format the above the created partition:
cmd# mkfs.ext4 <partition name>
Command Mount the formatted partition:
cmd# mount <partition name> <folder name>
Here we have to mount the partitioned storage into the “/var/www/html” folder, so that data from our website will be secured and not get lost if anything happens to the Root folder.
Now that we have configured the html folder in EBS volume we will write the html code in a folder with “.html” extension. Make sure to include an url (in place of “#”) for a static object(like an image) because we will work on the object in the next part of the blog.
What is S3 in AWS ?
Amazon S3 or Amazon Simple Storage Service is a service offered by Amazon Web Services (AWS) that provides object storage through a web service interface. Amazon S3 uses the same scalable storage infrastructure that Amazon.com uses to run its global e-commerce network. Amazon S3 can be employed to store any type of object which allows for uses like storage for Internet applications, backup and recovery, disaster recovery, data archives, data lakes for analytics, and hybrid cloud storage.
How to create the AWS S3?
You can create the S3 bucket in the AWS CLI using the following command. The following command creates a bucket named my-bucket in the ap-south-1 region. Regions outside of ap-south-1 require the appropriate LocationConstraint to be specified in order to create the bucket in the desired region:
$ aws s3api create-bucket — bucket <bucketname> — region ap-south-1 — create-bucket-configuration LocationConstraint=ap-south-1
How to upload Static objects in S3?
Here we will upload an image from our system using the CLI command shown in the image below. S3 storage provides an url to view the static objects from the browser and use it in other cases as well(in a website), thus we will use that link in our html codes(shown above) so that we can view that object in our website that we are creating using an EC2 instance. Then we will use S3 as the origin domain for Setting up a Content Delivery Network using CloudFront in the later part of the blog.
Command to upload a static object:
$ aws s3 cp image_path bucket_url
What is cloudfront?
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.
Content Delivery Network(CDN)
A content delivery network, or content distribution network (CDN), is a geographically distributed network of proxy servers and their data centers. The goal is to provide high availability and performance by distributing the service spatially relative to end users. CDN nodes are usually deployed in multiple locations, often over multiple Internet backbones. Benefits include reducing bandwidth costs, improving page load times, or increasing global availability of content. The number of nodes and servers making up a CDN varies, depending on the architecture.
For creating an CloudFront Distribution network we need to run the following command:
aws cloudfront create-distribution -origin-domain-name <domain_name>
After committing the above steps wait some minutes until it deploy the cloud delivery network. We need to provide the image url of CloudFront in our html code that we have written before for creating a webpage.
Now we can view our static object at a very high speed from almost all location around the globe. And with that we have successfully Created aHigh Availability Architecture with AWS CLI and webpage looks something like this,
Thank You for reading the Article!!!…