Create High Availability Architecture with AWS CLI

Anjaliray
7 min readMar 22, 2021

This architecture includes-
◼️ Launch EC2 instance
◼ Create EBS volume
◼Mount EBS volume to EC2 instance
◼Create an S3 bucket
◼Upload static objects such as images, videos, or documents in the S3 bucket
◼Create a content delivery network (CDN) using aws CloudFront distribution for S3 bucket.
◼️️ Configure instance as the webserver
◼Place CloudFront URL in an application for security and low latency
◼Deploy source code on EC2 instance webserver.

Brief Intro on what we have used in this Article.

What is AWS?

AWS (Amazon Web Services) is a comprehensive, evolving cloud computing platform provided by Amazon that includes a mixture of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings. AWS services can offer an organization tools such as compute power, database storage and content delivery services.

What is an EC2 instance?

Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster. You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic.

What is EBS?

Amazon Elastic Block Store (EBS) is a block storage system used to store persistent data. Amazon EBS is suitable for EC2 instances by providing highly available block level storage volumes.

What is S3 bucket?

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. This means customers of all sizes and industries can use it to store and protect any amount of data for a range of use cases.

What is Cloud Front ?

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.

What is CDN?

A CDN (Content Delivery Network) is a highly-distributed platform of servers that helps minimize delays in loading web page content by reducing the physical distance between the server and the user. This helps users around the world view the same high-quality content without slow loading times.

Now let’s start to practical part:

🔅 Webserver configured on EC2 Instance

Firstly will create a new key pair using this command :

aws ec2 create-key-pair — key-name <KEY_Name>

Goto aws ec2 dashboard and to check new key

Create a security group

To create a security group using following command:-

aws ec2 create-security-group — group-name ”GROUP_NAME” — description “DSCP”

To check security group is created or not, go to ec2 dashboard then click on security groups

Now, We have to launch one EC2 instance using above created key-pair and the security group using following command:

aws ec2 run-instances — image-id <image id> — instance-type <type> — count <number> — subnet-id <subnet-id> — security-group-ids <security-group-id> — key-name <key name>

To check create new instance or not.

So let’s now configure this instance as web server

For configuring the webserver on Ec2 instance we have to install httpd software which is a product of Apache. Following are the commands to install webserver :

  • yum install httpd
  • systemctl start httpd
  • systemctl status httpd
  • systemctl enable httpd

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

Here firstly we will create a EBS volume using this command :

aws ec2 create-volume — availability-zone <zone> — size <size> — volume-type <type>

To check EBS is created or not.

Now we will attach this EBS volume to our instance using this command :

aws ec2 attach-volume — volume-id <vol id> — instance-id <instance id> — device <name of device>

Now we have to do Partitioning, format, and mount our attached EBS volume.

Using fdisk -l we can verify EBS volume is attached or not.

To creating partitions we use command fdisk /dev/xvdf

Then press p for primary partition and press n to create a new partition then press w to save it.

To Format this volume use mkfs.ext4 /dev/xvda1

To connect new hard disk to O.S or instance we need a driver. For driver we use udevadm settle

To Mount this volume to Document Root Folder i.e /var/www/html we use mount /dev/xvdf1 /var/www/html

To insert file in /var/www/html folder do cd /var/www/html/

Then make a file into it and write what you want to see in your server

To see your data go to chrome write 172.31.39.61/lw.html, you could see your data

Static objects used in code such as pictures stored in S3

Firstly we have to create a S3 bucket using following command:

aws s3api create-bucket — bucket <name> — region <region> — create-bucket-configuration LocationConstraint=<region>

To upload any file to S3 bucket use this command:

aws s3 cp <path> s3://<bucketname> — acl public-read

Now we have successfully saved our static data to the S3 bucket. We can use the link of our file to add in our HTML code.

To see your data go to chrome write 172.31.39.61/lw.html, you could see your data,now it’s coming from S3

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

Firstly we have to set up Content Delivery Network using CloudFront in Amazon-CLI by this command:

aws cloudfront create-distribution — origin-domain-name <name of bucket>.s3.amazonaws.com

Opening cloudfront link of the image

Now we have successfully saved our static data to the S3 bucket. We can use the link of our file to add in our HTML code.

To see your data go to chrome write 172.31.39.61/lw.html, you could see your data, but now it’s coming from cloudfront

Finally, our webapp is created with High Availability Architecture.

Thank you for reading !!

--

--