Creating High Availability Architecture with AWS CLI
In this article, I will be telling about how I created a High Availability Architecture using AWS CLI.
To understand it better you should have little knowledge about AWS. In this architecture I have the done the following:
- 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.
Let’s dive into the Steps:
Before that, I have launched a pre-created instance through the cli. This instance have the Public-IP : “13.232.197.235”.
I have then entered inside the instance:
Now let’s start the steps:
- Web-server configured on EC2 Instance.
For this, The Web-server I have chosen is Apache Web-server. We installed the Apache Web-server through the command: “yum install httpd -y”.
The Document Root of Apache Web-server is located at “/var/www/html”. We have to make this persistent so that if we re-launch the instance our website content is safe.
2. Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
At first we have no content in the “/var/www/html” folder.
Now we attached the EBS Volume to the Instance and mount that volume to the “/var/www/html” folder. After mounting the EBS Volume to the “/var/www/html” folder and we have some data available.
3. Static objects used in code such as pictures stored in S3.
After attaching the EBS Volume, we have to create a S3 Bucket where we store our static files or images. Before writing the command and executing it, the S3 Bucket is empty.
After writing the command : “aws s3 mb s3://clibucket12” and executing it, we have the S3 Bucket created.
After creating the S3 Bucket, I uploaded the local image in the bucket through the command : “aws s3 cp 1.jpg s3://clibucket12/1.jpg” .
We have our image in the S3 Bucket.
4. Setting up Content Delivery Network using
CloudFront and using the origin domain as S3 bucket.
Now we create a CloudFront Distribution with origin name set to S3 Bucket. The command to do is this : “aws cloudfront — origin-domain-name clibucket12.s3.amazonaws.com” .
After the command we can check through the GUI also that CloudFront with S3 Origin has been created.
After that I updated the source of the image in the Apache Web-server to the domain name and we can see the site.
Thank you for reading.