👋 Welcome
A.A.

Hands-on AWS EC2 | ( Let's Deploy a website on EC2 )

👨🏻‍💻 Let's Do some real practice on EC2

Photo by Sergey Zolkin on Unsplash

Overview

  • We will be creating an EC2 instance, and then perform following operation on it.
  • What we will Learn: AWS EC2, Networking, SSH (cmd, PowerShell can work), Apache server,

Step-1 : Open EC2 Dashboard

  • Login to the AWS Management console
  • Search EC2 in the search bar and open it.

EC2 Dashboard

Step-2 : Create an EC2 Instance

  • in the Ec2 dashboard, find the ‘Launch Instance’ option and click on it.

Launch Instance Button

Step-03: Fill out the Asked details and then click on ‘Launch Instance’ to create it.

  • Provide any name of your choice:

Instance Name

  • In Application and OS Images(AMI):
    • select any operating system as per requirements.
    • for this particular article, I am going with 👇🏻 this one…

AMI Selection

  • In Instance Type: this is the configuration of the virtual machine.
    • Select t2.micro (default/free)

Instance Type Selection

  • Key Pair: required to access the instance from a remote device.
    • we can create a new key pair or use an existing one.
    • Create a new one with default options.
    • key pair should be available on pc for later use. So, download it and keep it safe.

Key Pair Creation

  • as we are not familiar with the security group, or traffic. So, leave the rest as default.
  • click on ‘Launch instance’

Step-04: SSH into Your Instance

  • Go to EC2 instance page
  • select instance
  • then click on the ‘connect’ option from the menu

Connect to Instance

  • look in SSH Client and coppy the example command from ther
    • also readout other details there …

SSH Client Command

  • open CLIin the same directory where ‘key pair’ is stored
  • then run the example command there and type ‘yes’ for any prompt(see the image)
  • after successful implementation, you may notice that the user name is changed to ec2user.
  • this means we are successfully logged to our remote EC2 instance/Virtual machine/remote computer. 😎
  • Now we can perform multiple tasks on that instance, through this local terminal.

SSH Connection Success

Step-05: Configure EC2 Instance as a Web Server

For this I will be installing an “Apache server”. (well I am doing chatGPT for this part 🤖)

Now execute the following command in your local terminal

  • sudo yum update // yum alternative of apt //update all the files
  • sudo yum install httpd // httpd is the name of the Apache HTTP Server's main executable file
  • sudo systemctl start httpd //This will run start apache server
  • sudo service httpd start // older version // start apache server
  • sudo systemctl status httpd // check status of server
  • sudo service httpd status // older way // check status of apache server.
  • sudo systemctl stop httpd // Don’t run it now 🤖// stop HTTP server

Now our server is live ; let’s first confirm it

  • [Note] This might not work for you, to resolve look at the ‘last step’ of this article.
  • Go to the instance dashboard
  • copy the public IP address and paste it on a new tab.

Public IP Address

  • So I got this page & you will get it too. 👨🏻‍🎓 (if not, check the last step 🤖)

Apache Test Page

Congrats apache server is working.

Step-06: Create and Publish a Sample test.html File

  • sudo nano /var/www/html/test.html //This will create a test.html file and will open the nano editor to put some content there.
  • write HTML code there and save it.
  • now you are good to go. 😎 site is live 👇🏻
  • http://your-ec2-public-ip/test.html

Test HTML Page

⭐⭐⭐

Well, Just deployed the Dictionary app on EC2 server

Dictionary App on EC2


Last Step: If unable to access the site using a public IP

So let's have a bird's eye view on networking.

This world is trashed with billions of devices. these devices can end up in the wrong place, with the wrong people. Hence there is a lot of concern with the accessibility and safety of the site..

So to handle these cloud platform uses Networking concepts like security group, inbound rule, outbound rule, etc.

  • Inbound rule: defines who can come in and access these contents.

> Now In our case, we need to correct this so that everyone can access this instance

  • go to the instance page ; find security group ; click on it

Security Group

  • find inbound rule ; click on “edit inbound rules”

Inbound Rules

  • Now add a new rule with the below configuration ; click on ‘save’ button

Edit Inbound Rules

Now try to access the site using the public address again... 🤖

— End —