Let’s see how we can do Web Hosting and create an architecture with high availability by using some of the services of the AWS. Here we are going to know, how to launch and use those different services from our Windows Command Line.
Services from AWS used in the process are :
- CLOUD FRONT
Before we begin, first we have to configure our AWS CLI. The steps are :-
- Login to your AWS root account in AWS WebUi.
- Create an IAM user, set it’s permission to Power User Accesss.
- Copy your Access Key and your Secret Key.
- Open your Windows CLI, and type “aws configure”
- Enter your Access Key, Secret Key, Format(default) and Region.
Now let’s get started..
1. We have to configure our webserver on the EC2 instance.
~ Webservers use http protocol which limits the power of the clients to only access the webpage. In order to get this webserver access to the clients we have to install a software called “httpd” in our EC2 instance and start its services.
- To install httpd software :-
#yum install httpd
#systemcrl enable httpd
~ In order to make our data persistent we should avoid storing it on the root drive. Therefore, we have to attach another separate hardisk to our instance.
2. We have to attach an EBS volume to our instance.
- To launch an EBS volume :-
Cmd : aws ec2 create-volume --availability-zone ap-south-1a --volume-type gp2 --size 1
- To attach the EBS volume with the EC2 instance :-
Cmd : aws ec2 attach-volume --volume-id vol-06c4d4e8e33c76b68 --instance-id i-0ea5f9341fc23f7f9 --device /dev/sdh
~ After attaching another hardisk, in this case an EBS volume we have to create partitions inside it in order to store our data there.
~After creating a partition we have to format the partition and mount it to a directory which is ( /var/www/html) also know as the “Document Root”.
- To format partition :-
Cmd : mkfs.ext4 /dev/xvdh1
- To mount partition with document root:-
Cmd : mount /dev/xvdh1 /var/www/html
~ Then we create a file with .html extension in the document root. This file will contain the html code of our webpage.
- .html file creation in the document root.
- Basic html code for the webpage.
3. Launch S3 object storage, in order to save the object URL in our html code.
- To create a bucket in s3 :-
Cmd : aws s3 mb s3://s3soupbucket1
- S3 bucket launched in AWS.
- To list the S3 buckets :-
Cmd : aws s3 ls s3://s3soupbucket1
- To upload an image file from our console to S3 :-
Note : First we have to manually go the path where the image is been located.
Cmd : aws s3 cp Soup.jpeg s3://s3soupbucket1
- To get the URL of the object in the S3 bucket :-
Cmd : aws s3 presign s3://s3soupbucket1/Soup.jpeg
~ Using S3 to save our webpage images will make our images more durable and will allow us to set up cloud front by using origin domain as S3 bucket.
4. Creating a Cloud Front distribution.
- To create a cloud front distribution :-
Cmd : aws cloudfront create-distribution --origin-domain-name s3soupbucket1.s3.amazonaws.com --default-root-object Soup.jpeg
- Cloud Front configured in AWS CLI.
- To see the image in s3 with Cloud front service :-
~ Using cloud front in AWS as a content delivery network will make our images appear super fast. It will create a local cache of our image in the nearest edge location which results in lowering the latency.
~ Integrating cloud front will make our webpage more secure as it gives us access to the Global Private Network of AWS.
- Website Url :-
Url :- http://126.96.36.199/soupws.html
- To see the image in S3 with Cloud front service integrated :-
Url :- http://d8k4by5s6vkls.cloudfront.net/Soup.jpeg
~ A special thanks to Vimal Sir ! ✨