Deploying a Webserver on AWS using CLI

Deployed a webserver using Ec2, EBS, s3, and CloudFront

mazon Web Services is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis.AWS enables you to select the operating system, programming language, web application platform, database, and other services you need. With AWS, you receive a virtual environment that lets you load the software and services your application requires.

We used mainly 4 services of AWS those are:-


An EC2 instance is a virtual server in Amazon’s Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure. AWS is a comprehensive, evolving cloud computing platform; EC2 is a service that allows business subscribers to run application programs in the computing environment.


The Basics. EBS starts out really simple. You create a volume from 1GB to 1TB in size and then you mount it on a device (such as /dev/sdj) on an instance, format it, and off you go. Later you can detach it, let it sit for a while, and then reattach it to a different instance.


Object storage built to store and retrieve any amount of data from anywhere. Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.


Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.

Following are steps for deploying Webserver on AWS

Step 1: Creating a security group (Firewall configuration)

aws ec2 create-security-group — description “Allow 22 & 80 Ports” — group-name “server_sec”

Step 2: Allow for ssh protocol ie. allow port 22 for login via putty and port 80 for accessing the web-server.

aws ec2 authorize-security-group-ingress — group-name “server_sec” — protocol “tcp” — port 22 — cidr “”

aws ec2 authorize-security-group-ingress — group-name “server_sec” — protocol “tcp” — port 80 — cidr “”

Step 3: We have the key already, and the security group so we are ready to launch the instance.

aws ec2 run-instances — image-id “ami-098f16afa9edf40be” — instance-type “t2.micro” — key-name “arth-aws” — security-groups “server_sec”

Step 4: Giving tag (name) to the instance so that we can easily identify the instance.

aws ec2 create-tags — resource i-0a88bc7ade8c450cd — tags Key=Name,Value=arth-webServer

Step 5: Now our instance is ready, So we will attach one EBS volume to make the data persistent.

aws ec2 create-volume — availability-zone “us-east-1c” — size 1

Step 6: So our EBS is created so it’s time to attach the EBS volume to the EC2 instance.

aws ec2 attach-volume — device “xvdb” — instance-id “i-0a88bc7ade8c450cd” — volume-id “vol-02eb7684507e9f310

Step 7:Now the EBS storage is attached to the EC2 instance, So we need to login via ssh and do further things so that we can deploy web-server on top of it.

We will use putty here for connecting the instance via SSH protocol

Here We have to provide the public IP address of the instance and key of the instance.

Step 8: We have to log in as root user in the instance as root have all the access in the OS.

sudo su — root

Step 9: Now we have to install the Apache server on our instance

yum install httpd

Step 10: As we install the Apache Web-server, Now we have to start the Web-server

systemctl start httpd

Step 11: So let's see our server is started or not

systemctl status httpd

Step 12: Now we have to check how many drives/volumes does the instance is using, With the following command:-

Step 13: Now you have to do the partition of the volume to use it. But for doing the partition of volume you have to go inside the disk.

Step 14: So as we are in the new volume we have to partition. Follow the command for the partition

Step 15: Partition is done, now we have to format the volume using the below-mentioned command.

mkfs.ext4 /dev/xvdb1

Step 16: After formatting the volume I am going to mount the new volume to the /var/www/html folder where I am going to save my code.

Step 17:Now we are creating a bucket to save all the static data of the webpage using the below-mentioned command.

aws s3 mb s3://bucketname

Step 18: To copy all the static data in the S3 bucket

aws s3 cp “C:\users\my first backup.bak” s3://my-first-backup-bucket/

Step 19: Now our data is uploaded, But we want to upload this data to the edge location for faster rendering for that we used the CloudFront.

aws cloudfront create-distribution --origin-domain-name

Step 20: Now we have to just past the link into our code.

Step 21: Now we need to copy our code from our local machine to our EC2 instance. For that, we will use the WinSCP application.

For that, we have to give our public IP, username, and key of instance.

Step 22: After transferring the data if we have to check the data we use the following.

Step 23: This we have to move this data to the /var/www/html folder.

Step 24: Now the code is placed in the respective folder. So we have to give permission.

setenceforce 0

Step 25: Now we can see our website by providing the public IP of our EC2 instance.


Voila!!! Our Website is now hosted by the webserver we configured. Here the code is in external EBS volume, static data is in S3, Hosted on EC2 instance. In this Way,I Hosted My Site.

A computer Engineer Student

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store