Create High Availability CloudFront Distribution with AWS CLI.
What is AWS S3 ?
Amazon Simple Storage Service is storage for the Internet. It is designed to make web-scale computing easier for developers.
Amazon S3 has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.
This guide explains the core concepts of Amazon S3, such as buckets, access points, and objects, and how to work with these resources using the Amazon S3 application programming interface (API).
What is AWS CloudFront ?
CloudFront is a CDN (Content Delivery Network). It retrieves data from Amazon S3 bucket and distributes it to multiple datacenter locations. It delivers the data through a network of data centers called edge locations. The nearest edge location is routed when the user requests for data, resulting in lowest latency, low network traffic, fast access to data, etc.
Prerequisites:-
- Create a key pair
- Create a security group
- Launch an instance using the above created key pair and security group.
- Create an EBS volume of 1 GB.
- The final step is to attach the above created EBS volume to the instance you created in the previous steps.
You can refer link given below for above requisite:-
What does 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.
→ Here all the above steps must be done using AWS CLI.
All the program will do on root user.
Firstly, we will install Apache httpd webserver on our Instance launched on AWS.
→ Firstly, we need to install Apache httpd software using the following command:-
Yum install httpd
when you install the httpd use the following commands to create file:-
1. cd /var/www/html/
2. vi aws-cli-shu.html
3. We will give the content in the index.html file.
4. systemctl start httpd
To permanent enable the httpd use “Systemctl enable httpd”.
In the above Image I Have not given any Background image . I will do it when I willupload the data in the S3 bucket See below for more description.
→Creating the partition :
To Create Partitions we Use fdisk /dev/xvdf command and after that just press enter and enter.
Formatting the partition :
To format, we use → mkfs.etx4 /dev/xvdf1 command
Mount the partition:-
→ Mount The Partition at Root directory of Httpd (/var/www/html)
mount /dev/xvdf1 /var/www/html
We can check mount point by following command :-
df -h or lsblk
→ Now we will create S3 bucket.
aws s3api create-bucket — bucket bucketname — region ap-south-1 — create-bucket-configuration LocationConstraint=ap-south-1
The bucket name must be unique .
Here the public URL of the uploaded image , anybody can access this image anywhere but must All the permission should be public.
Now check from the web portal.
https://<ip of your instance>/<name of file>
Now the web page look like, here I given the Public image URL where I uploaded the image in the S3 Bucket .
→ To create CloudFront Distribution for our S3 Bucket Objects .
aws cloudfront create-distribution — origin-domain-name {domain_name}
Our webserver is successfully launched, this static image is stored in Cloudfront .
Thanks for reading , Hope this will helpful.
LinkedIn URL:-linkedin.com/in/shubham-khandelwal-a04613144