Create a High-Availability Architecture Using AWS CLI
How many Ways you can communicate with AWS?
So there are 3 ways to used AWS Public:
1) WEBUI
2) CLI(Command Line Interface)
3) Scripting(Program)
So today we are going to all the things on AWS using the Second way i.e using CLI(Command Line Interface).
Steps for Todays Tasks is:-
⭕ Webserver 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 Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
⭕Finally place the Cloud Front URL on the webapp code for security and low latency.
Requirements:-
⭕Install AWS CLI Program
⭕Add to Your Environment Path
⭕Create a IAM user in AWS
⭕Configure using below command(In your cmd) and provide Access and Secret Key
aws configure
🎯For Creating this kind of architecture we are going to Integrate AWS S3 with CloudFront Service of AWS
So let's the Practical Part:-
1) First we have to launch instance by creating own security group and key pair using that we launch instance.
i) Create Key Pair:-
// Create a Key-Pair aws ec2 create-key-pair --key-name awscli
ii) Create a Security Group and Assign inbound rule to the Security Group:-
// Create a Security Group aws ec2 create-security-group --group-name myawssecurity --description mytask2 // Assign Inbound Rule aws ec2 authorize-security-group-ingress --group-name myawssec --protocol tcp --port 80 --cidr 0.0.0.0/0 // For SSH aws ec2 authorize-security-group-ingress --group-name myawssec --protocol tcp --port 22 --cidr 0.0.0.0/0 // Give Tag Name to Security group aws ec2 create-tags --resource --tags Key=name,Value=MySecurity
2) Launch Instance using above key pair and Security Groups.
// Launch instnace using above key pair and Security group aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --count 1 --subnet-id subnet-b6d5a3fa --security-group-ids sg-00c59775fe7fc4eae --key-name awscli
3) Connect to instance and configure Apache Webserver init and Start the Services of Webserver.
// Install Webserver(httpd server) yum install httpd -y // Start Services of httpd systemctl start httpd systemctl enable httpd systemctl status httpd
4) Create a Volume and Attach it with running current instance.
// Create a Volume aws ec2 create-volume --availability-zone ap-south-1b --size 1
// Attach a Volume to the instance
aws ec2 attach-volume --device /dev/xvdf --instance-id i-0efb81a7834fa733c --volume-id vol-08563de3e91b39a96
5) Create a Partition and format the volume and mount with /var/www/html folder.
Mount with /var/www/html folder of Apache webserver because all the code by default are present in that folder only.
6) Create a S3 Bucket.
//Create a S3 Bucket aws s3api create-bucket --acl public-read-write --bucket my-bucket4321 --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1
7) Upload Image in S3 Bucket.
8) Copy S3 bucket object url to our main code to see image and by using public ip of our instance we can see our site.
9) Create a Cloud Distribution for low latency and delay.
//Create a Cloud Distribution aws cloudfront create-distribution --origin-domain-name my-bucket4321.s3.amazonaws.com