Creating an High Availability Architecture With AWS CLI — including Webserver Configuration EBS, S3 & CloudFront & their Integration.
What we are going to do in this blog?
Create High Availability Architecture with AWS CLI
The architecture includes-
- 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 a S3 bucket.
- Finally, place the Cloud Front URL on the web app code for security and low latency.
So first i am going to start the instance using CLI in which i have to configured web server:
for the confirmation let’s check using WebUI
Now let’s install the httpd server on the instance .Before that i have to remote login to my instance using putty ,after login ;to install httpd we have yum command:
#yum install httpd
we have successfully installed the httpd on the instance
Creating an EBS Volume:
for creating the EBS volume of 1 GB we have the command-
# aws ec2 create-volume — availabilty-zone <AZ > — size <size in GB>
Let’s see on WebUI
Now i am going attach this volume to our instance:
To attach the above created EBS volume of 1GB to our instance we have the command :
# aws ec2-attach-volume — device /dev/xvdf— instance-id <instance id> — volume-id <vol id>
Let’s see on WebUI:
Now i am going to create partition on attached Volume:
Document Root(/var/www/html) made persistent by mounting on EBS Block Device:
Now i am going to start web service by systemctl command:
#systemctl start httpd
Now i am creating a html file inside /var/www/html directory
now disable the selinux security to avoid error while connecting to webpage
Now let’s check that our page is working or not for this we have go to url
https://3.6.93.234/myweb.html
its working good
Now we are going to create s3 bucket for static files:
to create the s3 bucket we have the command:
# aws s3api create-bucket — bucket “name” — create-bucket-configuration LocationConstraint= “region name"
Now i am going to put an image in the bucket, for this we have the command:
aws s3api put-object — “bucketname” — acl “access policy” — body “path of object or image” — key “any name for this object”
Let’s check on WebUI:
Now last step is to create the CloudFront distribution and integrate it with s3 and webserver:
to create cloudfront distribution we have the command:
aws cloudfront create-distribution — origin-domain-name “bucket path”
Lets check on WebUI
Now add image using cloudfront url in our html file:
Now let’s it is working or not:
Great it is working ,so finally we have achieved our goal.
for any query ping me on LinkedIn:
Thanks to my mentor Mr.Vimal Daga for giving such great sessions.
Connect with my mentor on LinkedIn: