🔰 Create High Availability Architecture with AWS CLI 🔰
Hello readers in this blog I am going to show you how to setup a high availability architecture using AWS.
High availability architecture is an approach of defining the components, modules or implementation of services of a system which ensures optimal operational performance, even at times of high loads.
So What we are going to do today is:-
- Webserver configuration 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.
OK, So lets start creating our own personalized architecture.
Note: For performing this task it is compulsory to configure AWS CLI on your system. Click Here to know how to configure AWS CLI on Windows.
Step 1 :- Configuring web server on ec2 instance.
To launch a instance we have to create a key pair first, which will later use to access the instance.
After executing the above command you will see a key on console kindly copy it in a .pem extension file. It will be used to access our instances.
Now we have to create a security group and add rules to it. Execute the below commands to create a security group and add rules.
Now we are all set to launch a instance. To launch a instance run the commands below.
Now our instance is launched, It’s time to access the launched instance.
Now SSH to the instance launched using the same private key saved. For SSH you can use SSH from command line or third party software. Here I am using Putty to connect to instance.
Now Change the user to root user to install software or use sudo with the commands. Use the command below to install web server. Here I am using Apache web server and using RedHat 8 therefore the package name is httpd.
yum install httpd -y
After Successful install, Start the httpd services by running “systemctl start httpd”. After running check whether the web server is running or not by entering public IP of the ec2 instance in any of your web browser.
If you guys are seeing the above page in your browser after entering your IP address, then installation is successful.
Step 2:- Now we have to mount a EBS volume in a /var/www/html folder to make the data of our website persistent.
To create a EBS volume run the following command in windows cmd.
Now attach the following volume with the instance we create before.
Note: It is compulsory that your instance as well as new EBS volume are in the same zone.
Now the volume has been attached, Now we have to check it in inside our instance.
Run “fdisk -l” to check devices connected to an instance. After Checking mount the device to document root of httpd software.
Now we have to first create a partition. To create a partition run the commands as I run in the below image.
Command I used above:
- fdisk /dev/xvdc (to create partitions in the new disk)
- mkfs.ext4 /dev/xvdc (to format the new partition)
- mount /dev/xvdc /var/www/html (to mount the partition to new folder/directory.)
Now our directory is successfully mounted, Now we are going to add some actual working code in the website.
Step 3:- Create a S3 bucket and store images on it..
To create a bucket go back to cmd and run the following commands: “aws s3 mb s3://bucket-name”
Now bucket is successfully created. Its time to store some objects over it. Use command “aws s3 cp file s3://bucket-name” to upload file.
Step 4:- Setting up cloudfront to deliver objects at low latency.
To create a distribution enter the command “aws cloudfront create-distribution — origin-domain-name bucket-name.s3.amazonaws.com — default-root-object file-name”
Now we received our URL for cloudfront CDN, This URL will deliver objects with very less latency.
Step 5:- Create a website containing objects from cloud front.
For creating website go to previously launched ec2 instance and create a basic code for website containing image name and the photo uploaded.
Now, Check whether our site is accessible or not. Just enter the public IP of the ec2 instance on which webserver is running in your browser.
Yeah!!! The site is working successfully. And it has a ultra fast latency in any region in the world.
Thanks for reading this blog guys….
If you have any doubts,
You can reach me at my linkedin