How to Launch EC2 Instance and Hosting static website by using AWS CLI in Ubuntu terminal

How to Launch EC2 Instance and Hosting static website by using AWS CLI in Ubuntu terminal

No alt text provided for this image

firstly run Ubuntu terminal and use command - apt-get install aws cli

than configure your cli to use this command - aws configure

after this command you see this type interface so configure with your access key

Now launch ec2 instances by using this commands ( aws ec2 run-instances --image-id ami****************** --count 1 --instance-type t2.micro --key-name ***** --security-group-ids ************* --subnet id ***************)

No alt text provided for this image

--->you can copy ami id by going to launch a instance

--->security group id can be taken in the same way by going to the security group

--->for subnet id you have to go the VPC service then click on the subnet then the following subnet ids of different availability zones will be appeared copy the subnet id of the specific availability zone which you want to launch in ec2

No alt text provided for this image

After that check your AWS console we'll get ec2 instance in EC2 dashboard than tab this instance and connect this instance with cli

No alt text provided for this image

Than we'll going to connect our instance to use following this command step by step

For connecting ec2 instance

  • first connect your ec2 instance
  • then go to the SSH client
  • copy the following

chmod 400 SONU.pem

ssh -i "SONU.pem" ubuntu@ec2-13-233-252-93.ap-south-1.compute.amazonaws.com

After copy that commands and we'll going to terminal and paste for connect your instance

No alt text provided for this image

first copy chmod 400 SONU.pem and paste terminal than go back ec2 interface and copy ssh url and paste in terminal than wait for this process than tab yes and done it.

After that we'll see our instance connect into ubuntu server

No alt text provided for this image

Than complete this process we'll need hosting into our instance server.

To host a static website we need to install apache2 sudo apt install apache2

apache is web servers are used to serve Web pages requested by client computers

No alt text provided for this image

After that running this command Sudo apt install apache2 -y we will find processing of apache2

No alt text provided for this image

Change the directory by using  cd /var/www/html

. After that you will find named index.html . you need to delete this file and create your own . The deletioning of the file requires sudo access so we need to run 

sudo rm -r index.html

after creating a new file named index.html by using this following command

sudo touch index.html

after run this command we'll give permission of read,write and execute index.html file. after that we run this  command to give permission ( sudo chmod +xrw file name). than we'll find our index.html file got permission to read,write and execute

after creating a new file named index.html we need to edit in it by using the command 

sudo vi index.html

After that we will get this interface-......here

No alt text provided for this image

"edit the text accordingly because the text which you enter will be displayed on the website"

---here i

welcome to the server 1

After seeing this interface we need to entering this interface file In which we write to edit our file. than press keyboard i key to insert something like as you want, i want to write ( welcome to the server 1) Than completing that we'll press escape (esc) .After escape (we have to press shift+:) pressing this key we'll going to end of this file. Than press wq (it stand for write and quit this file).

After that we'll seeing this interface.

After doing everything we'll check our server .Is our created file hosted or not? than we going to aws console account.

No alt text provided for this image

Copy the public IPv4 address of the connected server and paste it on the another tab to check whether the static website is hosted or not

No alt text provided for this image

After completing whole process we will get this interface. i am happy to share our web server hosting.

"ITS TIME TO CHEER UP BECAUSE THE STATIC WEBSITE IS HOSTEDD......"

------------------------------------------------------------------------------------------------------------------

To view or add a comment, sign in

More articles by Sonu kumar

Insights from the community

Others also viewed

Explore topics