Building High Availability Architecture with AWS CLI
Shreeja Raj
SDE-2 @Walmart | Former SDE Intern'23 @Amazon | Red Hat Certified Engineer | Leetcode 500+ | GEU'23
Welcome you all to my article based on Creating High Availability Architecture with AWS CLI.
Have you ever thought that how data of big Website and websites are accessible from worldwide??Is any tool behind it??
Yes.. By using CloudFront service which is provided by Amazon AWS we can host our website or data worldwide. But what is CloudFront??
Let’s see….
TASK DESCRIPTION:
?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 S3 bucket.
??Finally place the Cloud Front URL on the webapp code for security and low latency.
??All the above steps must be performed using AWS CLI ??
? For Designing these kind of architecture we are going to Integrate AWS S3 with CloudFront Service of AWS .
Let’s start with basic concept.
What is CloudFront?? ????
Amazon CloudFront is a content delivery network offered by Amazon Web Services. Content delivery networks provide a globally-distributed network of proxy servers which cache content, such as web videos or other bulky media, more locally to consumers, thus improving access speed for downloading the content.
What is Amazon S3??????
Amazon S3 is object storage built to store and retrieve any amount of data from anywhere on the Internet. It’s a simple storage service that offers industry leading durability, availability, performance, security, and virtually unlimited scalability at very low costs.
So Let’s start to our task !!!
TASK COMPLETION:
- Firstly we have to launch one EC2 instance for configuration of Webserver.
aws ec2 run-instances --image-id image_id --instance-type instance_type --count no --security-group-ids security_group_id --subnet-id subnet_id --key-name key_name
2. Now we have to create on EBS volume of required size.
aws ec2 create-volume — volume-type volume_type — size size — availability-zone name_of_zone
We can see our EBS volume is created.Now we want to connect to our created instance.
aws ec2 attach-volume --volume-id volume_id --instance-id instance_id --device device_name
3. Now the instance we created , we will ssh into that instance and install httpd..By running command :- ssh -l ec2-user -i keyname.pem public ip of instance
I) Installing httpd package
yum install httpd
4. Now we have to create partition to make document root /var/www/html.
I) Creating Partition
fdisk device_name
As we can see our partition is done. Now we have to format it.
II) Formatting Partition
mkfs.ext4 partition_name
III) Mounting /var/www/html on created partition.
mount partition_name /var/www/html/
5. Now we have to create one S3 bucket.
aws s3api create-bucket --bucket bucket_name --create-bucket-configuration LocationConstraint=ap-south-1
As our bucket is ready to use. Now we have to upload our data inside bucket.
aws s3 sync "location of image " s3://bucket_name --acl public-read
6. To access these Image We are now using S3 URL due to these we have to go travel through public Internet Network which may cause some kind of Delay or Latency or may be disconnection . Since Rather than Giving these Image URL we prefer AWS Cloud Front which is one kind of Content Delivery Network which provide one unique URL to S3 Object by which users from anywhere can access or see these content with less latency and fast connectivity via AWS Private CDN and Edge Locations .
To set up Content Deliver Network of AWS We have to create CloudFront Distribution for our S3 Bucket Objects .
aws cloudfront create-distribution --origin-domain-name domain_name
7. As CloudFront provides unique URL or Domain name to access our content worldwide with fast speed and low latency.
This is script. We can see image source is our unique domain name.
Let’s see output……