🔰CREATING HIGH AVAILABILITY ARCHITECTURE USING AWS CLI 🔰
Hello creators , here in this article i am going to show you a very interesting integration of amazon web services (EC2 , EBS, S3 , CLOUD FRONT) with the help of this integration i am going to create a architecture.
So lets start the making of architecture, before starting let me introduce to you what is aws cli.
🔰 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.
Why do we need amazon cli ?
AWS CLI gives you the ability to automate the entire process of controlling and managing AWS services through scripts. These scripts make it easy for users to fully automate cloud infrastructure. Prior to AWS CLI, users needed a dedicated CLI tool for just the EC2 service.
📍 Here is the link to download amazon cli 👇
https://awscli.amazonaws.com/AWSCLIV2.msi
After downloading amazon cli , install it and after installation done you can check in command prompt by command aws 👇
Now you have to configure your aws cli , means you have to authenticate your account on cli .
So for authentication you have to write the command aws configure 👇
Now as you can see in above picture it is asking for aws access key , aws security key so for this you have to create an IAM user this is also one of the service of AWS from there you can get your aws access key and aws security key . If you want how to know how to create IAM user you can go through this link👇
So we have authenticate our account through AWS CLI .
After doing this the requirements for this integration is one EC2 instance and One EBS volume so I am not going to show you here how to create you can refer to this link where I have shown you how to create EC2 instance and EBS volume.
Now after making the EC2 instance and EBS volume we have to configure the webservice in our instance .
How To Configure Web-Server?
To configure it you have to use the apache product called httpd and you have to install in your instance by the command yum install httpd 👇
Here your httpd comes with configuration part so you don't have to configure it .To check wether it install or not you can check by the command rpm -q httpd 👇
To start the service you have to write systemctl start httpd and to check the status after starting it use command systemctl status httpd
So we are going to make an html page, for this you have to go in the directory /var/www/html/ and to inside this directory use command cd /var/www/html/ . This directory comes only when you install the httpd product . Inside this directory we are going to make an html file with the name of web.html and to make this file we use command vim web.html
So now your html page is in your root directory and that root directory is mounted with your ec2 volume , so there is one disadvantage if in case your instance got crashed or any problem comes while opening your instance , then your data will be loss your , html page will be loss , instead of keeping this /var/www/html/ directory in main volume of ec2 we going to mount this directory with the EBS volume we created above . So to mount use command mount <Your drive name(suppose /dev/xvdf1) > </var/www/html> 👇
Now after mount your drive with directory you have made your data persistent or permanent you can check the status of mount by command df -h 👇
Here also there is one disadvantage in EBS volume that its availability % is 99.999 and data durability is 99.88% to 99.99% so we cant take the risk of keeping our static data like photo, video, pdf etc in EBS volume . So to keep this data safe we will use S3 service which provide availabilty of 5 9's and durability of 11 9's.
Inside this we have to make one bucket to store our static data .
🔰 How to create bucket using CLI.
Here i have created a bucket and while creating this bucket i have give public access . Its your choice to keep public or private and here i have give region name in which i have to create . S3 is the global service means you can access your bucket from any region .
I have created a bucket now i am going to deploy my static data of my html page.
🔰How to upload file in bucket though CLI.
Here I have uploaded the file inside the bucket and also I have give public access to my file.
Now I am going to copy that url of your file from s3 and put inside my html code.
🔰How to get url from CLI
Now our static data is safe , but again there is one issue and that issue whenever any user which is far from our location of static data he/she will face the problem of latency . For example I have created my bucket in Ireland and if any user from India opens my webpage then my static data will take time to open this is called latency .
Now to make the better user experience , we have to minimize the latency , for this AWS provide a service name Cloud Front.
🔰 What is cloud front ? How to use it ?
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. CloudFront works seamlessly with services including AWS Shield for DDoS mitigation, Amazon S3, Elastic Load Balancing or Amazon EC2 as origins for your applications, and Lambda@Edge to run custom code closer to customers’ users and to customize the user experience. Lastly, if you use AWS origins such as Amazon S3, Amazon EC2 or Elastic Load Balancing, you don’t pay for any data transferred between these services and Cloud Front.
You can get started with the Content Delivery Network in minutes, using the same AWS tools that you're already familiar with: APIs, AWS Management Console, AWS CloudFormation, CLIs, and SDKs. Amazon's CDN offers a simple, pay-as-you-go pricing model with no upfront fees or required long-term contracts, and support for the CDN is included in your existing AWS Support subscription.
🔰 How does CloudFront integrate with S3 AWS service
To speak of CloudFront being integrated with another AWS service chiefly refers to CloudFront’s ability to use that service as a data source for distribution. These integrations include:
Amazon S3. It’s possible (and in fact very common) to use an Amazon S3 bucket as a source from which CloudFront will request files before placing them in its edge locations. This works both with standard S3 buckets and with buckets configured as website endpoints. When CloudFront is configured, the S3 bucket can continue to be used with no changes.
🔰 How To Use Cloud Front Service From CLI
- Creating Distribution :
Creates a new web distribution. You create a CloudFront distribution to tell CloudFront where you want content to be delivered from, and the details about how to track and manage content delivery.
Origin
An origin is the location where content is stored, and from which CloudFront gets content to serve to viewers.
Domain name : Domain name means your bucket name in s3 from where your data will be delivered to local cache. Syntax :- <bucket-name>.s3.amazonaws.com
So to create distribution from CLI we use command aws cloudfront create-distribution --origin-domain-name 👇
So here I have created the distribution and this distribution will create cache in all 250 edge locations , after creation it will take some time to deploy in all the edge locations as you can see below it is in progress mode and after progress mode it will deployed .
After all this steps copy your domain name as you can see in the CLI window and paste inside your html code in place of S3 url
Syntax :- https://<domain-name>/<file-name.jpg> this syntax you have to provide in place of S3 url.
🔰 Benefits Of using CloudFront Domain name Instead Of S3 URL
- This will reduce the latency which is coming in case of S3 url because cloudfront service use amazon global private network which helps to secure and fast data delivery.
This the webpage I have created with the help of html 👇
📍 CONCLUSION
This is my architecture where I have shown you the integration of EC2+EBS+S3+CLOUDFRONT
😊THANK YOU FOR GIVING YOUR VALUABLE TIME FOR READING THIS ARTICLE😊
Hope you like this article , if you have any doubt regarding to this article you can feel free to ask in comments or you can ping me in my LinkedIn .
nice work
Good job buddy