Introduction to Amazon Elastic Compute Cloud (EC2)

Meriem Terki
7 min readNov 27, 2023

--

Looking to launch and configure a virtual machine in the powerful and dynamic Amazon Web Services (AWS) cloud?

Well, you’ve come to the right place! In this guide, you’ll gain practical experience using Amazon Machine Images (AMI) to launch Amazon EC2 instances and master the art of using key pairs for SSH authentication to log into your instance. Additionally, you will learn how to create a web page and publish it on your AWS virtual machine.

Introduction

What is EC2 ?

Amazon Web Services (AWS) provides a groundbreaking cloud service known as Elastic Compute Cloud (EC2), offering exceptional computing power in the cloud, where users can lease virtual machines, referred to as instances, which can be tailored to their exact computing requirements.

Here are some additional key points about Amazon EC2:

  • EC2 empowers users with complete control over their virtual computing resources, enabling them to personalize their instances with their chosen operating system, programming languages, and application servers.
  • Users can configure security groups and network access control lists (ACLs) to control inbound and outbound traffic to their instances, providing a secure environment for their applications.
  • EC2 offers various purchasing options, including On-Demand Instances, Reserved Instances, and Spot Instances, allowing users to optimize their costs based on their application requirements.
  • EC2 provides a wide range of monitoring and logging features, including Amazon CloudWatch, which allows users to monitor their instances, applications, and resources in real-time, and Amazon CloudTrail, which provides a record of all API calls made in their AWS account.
  • EC2 supports a variety of storage options, including Amazon Elastic Block Store (EBS), Amazon Elastic File System (EFS), and instance store volumes, providing users with the flexibility to choose the most suitable storage solution for their applications.
  • EC2 allows users to create custom machine images (AMIs) of their instances, which can be used to launch new instances with the same configuration and software stack, saving time and effort in application deployment.

Architecture Diagram

Task Steps

Step 1: Sign in to AWS Management Console

  1. On the AWS sign-in page ,enter your credentials to log in to your AWS account and click on the Sign in button.
  2. Once Signed In to the AWS Management Console, Make the default AWS Region as US East (N. Virginia) us-east-1

Step 2 : Launch an EC2 Instance with desired specifications

  1. Ensure you are in the US East (N. Virginia) us-east-1 Region to begin launching an EC2 instance in the Amazon cloud
  2. Navigate to EC2 by clicking on the Services menu in the top, then click on EC2 in the Compute section.
  3. Click on the Instances option on the left panel, and then click on the Launch Instances button.

4. Enter the name : Enter MyEC2Server

5. Search for Amazon Linux 2 AMI in the search box and select it by clicking on the Select button.

Note: if there are two AMI’s present for Amazon Linux 2 AMI, choose any of them.

6. An instance type in AWS refers to a virtual server configuration that determines the computing resources, such as CPU, memory, and storage, available to an instance. It is the basic building block for creating an EC2 instance in the AWS cloud.

  • For Instance Type: Select t2.micro

Note : t2.micro is an instance type in AWS that comes with 1 vCPU, and 1GB memory and is suitable for low-traffic web servers, small development environments, and other lightweight applications.

8. AWS key pair is a secure pair of keys used for login and access to EC2 instances. It includes a public key placed on the instance and a private key kept on the user’s local computer, used for authentication to prevent unauthorized access.

  • For Key pair(login): Select Create a new key pair Button
  • Key pair type: RSA
  • Key pair name: WhizKey
  • Private key file format: .pem

9. In Network Settings Click on Edit Button:

  • Auto-assign public IP: Enable
  • Select Create security group
  • Security group name: Enter MyEC2Server_SG
  • Description: Enter Security Group to allow traffic to EC2
  • We will now add the security group rules.

Note : SSH will already be present there.

  • For HTTP, Select Add security group rule Button
  • Choose Type: Select HTTP
  • Source: Select Anywhere

Note: security group is a virtual firewall that controls the inbound and outbound traffic for instances in a particular network in a cloud computing environment. Here we have selected SSH and HTTP rules that will allow incoming SSH and HTTP traffic to instances that are associated with the security group.

10. Proceed with launching the instance while leaving all other settings as default. Simply click on the Launch Instance without modifying any other configuration.

11. To view the instance that you have created, choose the View all Instances option.

12. Launch Status: Once you have initiated the instance launch process, Go to the Instances page from the left menu and wait for your EC2 instance to become “Running” while ensuring the health check status is 2/2 checks passed for optimal performance.

13. Select the instance that you have created and copy the public IPv4 address within the details section and paste it into the editor for later use. An example of this process is depicted in the screenshot provided.

Step 3 : SSH into EC2 Instance using the key pair

  1. Select your EC2 instance(MyEC2Server) and click on the Connect button.

2. Select EC2 Instance Connect option and click on Connect button.(Keep everything else as default)

3. A new tab will open in the browser where you can execute the Linux Commands.

Step 4: Install an Apache Server on the instance

In this step, our goal is to configure an Amazon EC2 instance to run an Apache Web Server and verify its functionality by accessing the web server via a web browser using the instance’s public IPv4 address.

  1. Switch to root user:
sudo su

2. Now run the updates using the following command:

yum -y update

3. Once completed, lets install and run an apache server

  • Install the Apache web server:
yum install httpd -y
  • Start the web server:
systemctl start httpd
  • Now Enable httpd:
systemctl enable httpd
  • Check the webserver status
systemctl status httpd
  • You can see Active status is running.

Note : You can test that your web server is properly installed and started by entering the public IPv4 address of your EC2 instance in the address bar of a web browser. If your web server is running, then you see the Apache test page. If you don’t see the Apache test page, then verify whether you followed the above steps properly and check your inbound rules for the security group that you created.

Step 5 : Create a web page and publish it on the instance

In this step, you will add content to the index.html file using the “echo” command and restart the webserver. Then, you can view the content by entering the public IPv4 address followed by “/index.html” in a web browser, ensuring that the URL protocol is HTTP.

  1. To add the contents into index.html file using echo, copy and paste the below command to shell.
echo "<html>Hi users, I am a public page</html>" > /var/www/html/index.html

2. Restart the webserver by using the following command:

systemctl restart httpd

3. Now enter the file name, /index.html after the public IPv4 Address which you got when you created the ec2 instance in the browser, and you can see your HTML content.

Note: If the index.html page is not loading, try removing s from the link, it should be HTTP.

4. . If you can see the above text in the browser, then you have successfully completed your job.

Note : the public IP address that you can see in the previous image isn’t the one that correspond to the previous steps(already mentioned in Step 5) because I‘ve capture this with another EC2 instance

You’re all done! Congratulations!

That’s all I have for today folks. Thank you for reading and/or following along! I hope this project was helpful and worth your while. Stay tuned for my next project on this journey into the cloud.

Let’s connect on LinkedIn! 👉 https://www.linkedin.com/in/meriem-terki-1295a1222/

--

--

Meriem Terki
Meriem Terki

Written by Meriem Terki

Data, Cloud & AI enthusiast| Follow me on my journey

No responses yet