DEV Community

Cover image for AWS Projects-EC2 Part 1: Creating an EC2 instance to display a Basic web page
Msaghu
Msaghu

Posted on

AWS Projects-EC2 Part 1: Creating an EC2 instance to display a Basic web page

Links to other labs

  1. IAM
  2. EC2 - Part 1

What is AWS EC2

AWS Elastic Compute Cloud(AWS EC2) is a web service that provides resizable compute capacity in the cloud.

With the web service interface of Amazon EC2, you can obtain and configure capacity with minimal friction. It provides you with complete control of your computing resources. You can run application servers, blogs, batch processing, and more.


Objectives for this exercise

  1. Launch our EC2 instance with termination protection.

  2. Monitoring an EC2 instance using CloudWatch.

  3. Updating your security group and accessing the web server.


Let's get into it

1. Launch our EC2 instance with termination protection.

  • Termination protection prevents a user from accidentally terminating an EC2 instance.

  • In the AWS Management Console on the Services menu, choose EC2.

  • In the left navigation pane, choose EC2 Dashboard to ensure that you are on the dashboard page.

  • Choose instances, and then select Launch instance.

EC2 dashboard

  • In the Name and tags section, for Name, I entered Web-Server

  • Choose the Add additional tags link.
    From the Resource types dropdown list, ensure that both Instances and Volumes are selected.

  • Locate the Application and OS Images (Amazon Machine Image) section. It is just below the Name and tags section.
    Select the Amazon Linux 2 AMI .

  • As we try to remain in the free tier range, we will keep the default instance type, t2.micro.

  • In the Key pair (login) section, from the Key pair name - required dropdown list, choose Proceed without a key pair.

  • In the Network settings section, choose Edit.

  • From the VPC - required dropdown list, choose the default VPC.

  • In the Network settings section, for Security group name - required, enter Web Server security group.

  • Since we don't want to access this VPC via SSH, we will delete the existing SSH rule, next to Security group rule 1, choose Remove.

  • In the Configure storage pane, keep the default storage configuration.

  • Expand the Advanced details pane then choose enable from the Termination protection drop down list.

  • To successfully start the web server, we paste the follwing code into the User data section

#!/bin/bash
yum -y install httpd
systemctl enable httpd
systemctl start httpd
echo '<html><h1>Hello From Your Web Server!</h1></html>' > /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode
  • We then click Launch instance.
    A successful EC2 instance launch

  • View all instances to confirm that its passed all checks.
    Image 2

2. Monitoring an EC2 instance using CloudWatch.

  • Choose the Status checks tab, then choose Monitoring tab.

Successful upload

  • To see if all packages were successfully installed, go to the top of the page, choose the Actions dropdown menu. Select Monitor and troubleshoot Get system log. We see that HTTP package was installed from the script above;

Monitor and troubleshoot

  • Return to the Amazon EC2 dashboard, by choosing Cancel.

  • With your Web-Server selected, go back to the Actions dropdown menu, and select Monitor and troubleshoot , Get instance screenshot.

Get instance screenshot

3. Updating your security group and accessing the web server.
Since we didn't choose any inbound rules, we will not be able to connect to our instance. We can check this by:

  • Select the check box next to the Amazon EC2 Web-Server that you created, and then choose the Details tab.

  • Copy the Public IPv4 address of your instance to your clipboard and paste in a new tab, you will get an error. Now let's change this:

Image browser

  • Leave the browser tab open, and return to the EC2 Management Console tab.

  • From the left navigation pane, choose Security Groups.

  • Next to Web Server security group, select the check box.

  • Choose the Inbound rules tab, where we will see that the security group currently has no rules.

Security group

  • Choose Edit inbound rules, and then choose Add rule and configure the following options:
    Type: Choose HTTP.
    Source: Choose Anywhere-IPv4.

  • Save the rules, then go back to the open tab and refresh. The page will now display your HTML document:
    Successfully deployed

Top comments (0)