Create High Availability Architecture with AWS CLI
What is AWS?
Amazon web service is a platform that offers flexible, reliable, scalable, easy-to-use and cost-effective cloud computing solutions.
What is AWS CLI?
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
So Let’s discuss about some services of AWS like-
1- IAM( Indentity Access Management)
2- Compute Service (EC2)
3- Storage Service ( EBS, S3)
4- CDN (Content Delivery Network Service) ( CloudFront )
So Let’s start
1- IAM( Indentity and Access Management)
AWS Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources. Using IAM, you can create and manage AWS users and groups, and use permissions to allow and deny their access to AWS resources.
2- Compute Service (EC2)
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers.
3.1- What is EBS?
Amazon Elastic Block Store (EBS) is an easy to use, high performance block storage service designed for use with Amazon Elastic Compute Cloud (EC2) for both throughput and transaction intensive workloads at any scale.
3.2- What is S3?
An Amazon S3 bucket is a public cloud storage resource available in Amazon Web Services’ (AWS) Simple Storage Service (S3), an object storage offering. Amazon S3 buckets, which are similar to file folders, store objects, which consist of data and its descriptive metadata.
4- 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.
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.
Now you have high level idea about these above service , now we will integrate all those services and create high availability architecture.
Task Description-
1- Webserver configured on EC2 Instance
2- Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
3- Static objects used in code such as pictures stored in S3
4- Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
5- Finally place the Cloud Front URL on the webapp code for security and low latency.
Let’s start doing task
Prerequisite for this task:-
1- Aws Cli setup installed properly
2- You have IAM User with Access key and secret key
3- Login Into cli prompt/terminal
run “aws configure” command and provide your access key & secret key
I have already complete all prerequisite if you have than it’s ok otherwise you can go above details and complete these.
Let’s start our task:-
1- Webserver configured on EC2 Instance
To configure webserver firstly we have to launch ec2-instance to launch ec2-instance using cli we use this command
“aws ec2 run-instances — image-id <value> — instance-type <value> — count <value> — subnet-id <value> — security-group-ids <value> — key-name <value>”
Now we will Configure webserver, To configure webserver we have to follow three steps
1- install the software(“httpd”)
2- Setup/configure it
3- Start the service.
Let’s follow above steps to configure webserver:-
To install the httpd software using cli without login we use this command
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo yum install httpd -y
First step has been done now follow next step start the services
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo systemctl start httpd
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo systemctl enable httpd
Let’s check status of httpd service
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo systemctl status httpd
Now your webserver configured properly to verify copy the public ip of your ec2-instance and paste it to in your browser
2- Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
- For this firstly we have to create one ebs volume
- than attach it to our instance
For creating ebs volume we use command:-
aws ec2 create-volume — availability-zone <value> — size <value>
For attaching ebs volume with instance we use :-
aws ec2 attach-volume — volume-id <value> — instance-id <value> — device <value>
We have created ebs volume and attach this volume with our instance but it is not sharing its storage to with ec2-instance, for using storage of this ebs volume we have to follow some steps
- Create a new partition in ebs volume
- Then Format this partition
- After format we have to mount it
Create a new partition in ebs volume:-
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo fdisk device_name( like — /dev/xvdf1 etc)
Format this partition:-
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo mkfs.ext4 <partition-name>( like — /dev/xvdf1 etc)
Now we have to mount it:-
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo mount /dev/xvdf1 /var/www/html
To verify that our partition mount successfully or not
ssh -l ec2-user <ip-of-instance> -i <keyname> sudo df -h
3- Static objects used in code such as pictures stored in S3:-
For this we have to
- Create a S3 bucket in aws
- Upload the data in s3 bucket using public read-write permission
- Copy the object link and paste it to in our code
Create a S3 bucket in aws:-
aws s3 mb s3://<bucket-name> — region <value>
Upload the data in s3 bucket using public read permission:-
aws s3 cp source s3://<bucket-name> — acl <permission>
To verify file successfully uploaded or not
aws s3 ls s3://<bucket-name>
Now the file uploaded successfully , s3 provide one link for this object , I have write simple html file on github and paste this url there, now Iwill download this file in my ec2-instance in /var/www/html
https://raw.githubusercontent.com/sabir69261/image/master/r.html
Now Your webserver retrieve your file from Amazon S3 Storage , copy your ec2-instance public ip and paste in browser with file name
http://ip:filename
4- Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket:-
aws cloudfront create-distribution — origin-domain-name bucket-name.s3.amazonaws.com
5- Finally place the Cloud Front URL on the webapp code for security and low latency:-
Now I will update cloudfront url in my github code and again download the file in same location.
https://raw.githubusercontent.com/sabir69261/image/master/r.html
Now copy your instance public ip and paste it on your browser
http://ip:filename
This images retrieving from cloudfront url.
Finally our high availability architecture created.
Thanks to VimaDaga Sir for guidance , supporting , motivating & providing right knowledge to us.
Thanks for reading.
Bye Bye signing off.