Creating High Availability Architecture via AWS Cloudfront using AWS CLI
Task Description📄
🔰 Create High Availability Architecture with AWS CLI 🔰
The architecture includes-
(1) Webserver configured on EC2 Instance
(2) Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
(3) Static objects used in code such as pictures stored in S3
(4) Setting up Content Delivery Network using CloudFront and using the origin domain as S3 bucket.
(5) Finally place the Cloud Front URL on the webapp code for security and low latency.
Steps for performing this task:
- Launch one EC2 instance having webserver running
- Create one EBS volume containing Source Code
- Create one S3 bucket having static objects (like images)
- Using above service host a globally accessible website via aws cloudfront for best user experience.
Lets start our practical:
Lets launch one AWS EC2 instance using AWS CLI
First , we have log in to our aws account
aws configure
In this we have to specify our ACCESS KEY and SECRET KEY to login into our AWS Account via CLI.See we can also specify our region in which we want to deploy above services as well as output format for AWS.
Now we are going to launch one EC2 Instance to run WEBSERVER Services on it.
So, Finally we launched on EC2 instance on ap-south-1a availability zone.
So, Finally our EC2 instance is launched we can see it come in AWS WEBUI.
Lets configure apache httpd webserver on it and start its services
Connect to our instance via ssh
See we have installed httpd software using yum and started its services on permanent basis even after reboot.
Now we have to start webserver services here
Now , Lets create our EBS volume of 1 GB to make our source code for our website permanent/persistent.
Remember you should create EBS in same Availability zone where you launched EC2 as EBS VOLUME SERVICE is ZONAL SERVICE.
See Finally our EBS volume is created.
Now, Lets attach this new available EBS volume to our EC2 instance.
See finally status of EBS changed from "available" to "in-use" as we have attached it to EC2 instance.
Lets mount document root /var/www/html to EBS volume to make it persistent:
But for this we have to create Partition in this new volume and format it.
Now, whatever code/content we put inside document root it would be persistent.
Lets create source code for our web page:
Now Lets create s3 bucket in ap-south-1 and upload this static image there:
Lets Put this image into s3 bucket and remove from local storage:
Lets copy this url and put into webpage code so that our webpage can fetch image from S3 rather than local storage:
Lets create CloudFront distribution service and specify origin-domain-name as our S3 Storage containing hackerone_image.
Now finally our Cloudfront distribution is created .
Now use this special url given by Cloudfront. This url is internally using Route53 service of AWS to recognize the nearby edge location to fetch this image in our webpage.
Cloudfront also provides lots of monitoring services to know viewers of our webpage.
Well done ✨👏🏻Shubham Bhardwaj