> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to Amazon Elastic Compute Cloud (EC2)

> Hands-on lab · 30m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/introduction-to-amazon-elastic-compute-cloud-ec2" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab Details

1. Welcome to this comprehensive lab that will guide you through the process of launching and configuring a virtual machine in the powerful and dynamic Amazon Web Services (AWS) cloud.
2. In this lab, you will 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.
3. Duration: **30 minutes**
4. AWS Region: **US East (N. Virginia) us-east-1**

### Introduction

#### What is EC2 ?

Amazon Web Services (AWS) offers a revolutionary cloud-based web service called Elastic Compute Cloud (EC2) that provides unparalleled compute capacity in the cloud. In this cutting-edge platform, users have the ability to rent virtual machines, called instances, that are fully customizable to meet their specific computing needs.

Here are some additional key points about Amazon EC2:

* EC2 provides users with full control over their virtual computing resources, allowing them to customize their instances with their preferred 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.

With its powerful features and flexibility, EC2 has become a go-to choice for developers, businesses, and enterprises alike, providing the foundation for scalable and robust cloud-based applications.

### Architecture Diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/001.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=f37ac4c505596a8b765da30dc46ee9da" alt="" width="660" height="780" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/001.png" />

### Task Details

1. Sign in to AWS Management Console
2. Launch an EC2 instance with desired specifications
3. SSH into the EC2 instance using the key pair
4. Install an Apache server on the instance
5. Create a web page and publish it on the instance

### Launching Lab Environment

1. To launch the lab environment, Click on the **Start Lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM user name**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

> **Note** : You can only start one lab at any given time

## Lab guide

### Lab Steps

#### Task 1: Sign in to AWS Management Console

1. Click on the **Open Console** button, and you will get redirected to AWS Console in a new browser tab.
2. On the AWS sign-in page,

   * Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
   * Now copy your **User Name** and **Password** in the Lab Console to the **IAM Username and Password** in AWS Console and click on the **Sign in** button.
3. Once Signed In to the AWS Management Console, Make the default AWS Region as **US East (N. Virginia) us-east-1.**

#### Task 2: Provision Default VPC

1. Navigate to **VPC** by clicking on the **Services** menu in the top, then click on **VPC** or Open the Amazon VPC console via [https://console.aws.amazon.com/vpc/.](https://console.aws.amazon.com/vpc/)
2. Delete the **default VPC** by following the **below steps:**

   * In the navigation pane, choose **Your VPCs.**
   * Select the **VPC** with value as **yes** in **default VPC column.**

     <img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/002.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=337179260b66c1beca69df9ee5e071e8" alt="" width="1222" height="154" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/002.png" />

* Go to **actions button** and click on **delete VPC button**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/003.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=d0cb1b05051867ddc75097033b87560f" alt="" width="1222" height="276" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/003.png" />

* Check **I acknowledge that I want to delete my default VPC** option.
* Type default delete VPC and click on **Delete button.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/004.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=d85d27ad7d5a88dadb01616958f318cf" alt="" width="832" height="806" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/004.png" />

3. Now to provision **Default VPC** again, Refresh your console go to **actions** and click **Create default VPC**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/005.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=311b92bf2e326ab0661618b370fb5922" alt="" width="1222" height="283" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/005.png" />

4. Click **Create default VPC button** and your default VPC will get created

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/006.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=59a6593158291a3087c2bd00d6e5cec9" alt="" width="1222" height="221" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/006.png" />

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/007.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=603375f99cc89a341fcad414a68f5e49" alt="" width="1222" height="161" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/007.png" />

#### Task 3 : 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. Name : Enter **MyEC2Server**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/008.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=e77941e66dfddb74d977b25b3317c35f" alt="" width="1222" height="160" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/008.png" />

5. Select **Amazon Linux 2023 AMI** from the dropdown.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/009.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=3ed514ea39d242faf3c5fcbf9811024c" alt="" width="1215" height="652" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/009.png" />

   > **Note:** if there are two AMI's present for **Amazon Linux 2o23 kernel-6.1 AMI**.

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**

     <img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/010.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=18c83d50449ced433a3ac90844bcc2fa" alt="" width="1222" height="290" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/010.png" />

* 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.

7. 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 name: **WhizKey**
* Key pair type: **RSA**
* Private key file format: **.pem**

8. 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.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/011.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=890f826bb2033f8fd20eb07be8aed7f7" alt="" width="1222" height="471" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/011.png" />

9. We will now add the security group rules. SSH will already be present there.

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

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/012.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=632a5e0b4b1230be718944b6c0000aba" alt="" width="1222" height="822" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/012.png" />

10. A 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.
11. Proceed with launching the instance while leaving all other settings as default. Simply click on the **Launch Instance** without modifying any other configuration.
12. To view the instance that you have created, choose the **View all Instances** option.
13. **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.

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/013.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=b2b922ad01de198ca1af2f6abfe9705f" alt="" width="1222" height="202" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/013.png" />
14. **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.

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/014.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=ded6b336c56c02a5f48891f379ef3a0f" alt="" width="1222" height="218" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/014.png" />

#### Task 4 : SSH into EC2 Instance using the key pair

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

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/015.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=78d6bf3004b7b535fbe665ffcc360b4d" alt="" width="1222" height="163" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/015.png" />

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.

4. Please follow the steps in [SSH into EC2 Instance](https://play.whizlabs.com/site/task_support/ssh-into-ec-instance) for more options to SSH.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/016.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=4c19e2ccb7c5e4fcca66fd98c877bcd7" alt="" width="1222" height="462" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/016.png" />

#### Task 5: Install an Apache Server on the instance

In this task, 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:

   ```javascript theme={null}
   sudo su
   ```

2. Now run the updates using the following command:

```python theme={null}
dnf update -y
```

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

4. Install the Apache web server:

```python theme={null}
dnf install httpd -y
```

5. Start the web server:

```python theme={null}
systemctl start httpd
```

6. Now Enable httpd:

```python theme={null}
systemctl enable httpd
```

7. Check the webserver status

```python theme={null}
systemctl status httpd
```

8. You can see Active status is running.

9. 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.

#### Task 6 : Create a web page and publish it on the instance

In this task, 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.

   ```python theme={null}
   echo "<html>Hi IP Lab Portal, I am a public page</html>" > /var/www/html/index.html
   ```

2. Restart the webserver by using the following command:

```python theme={null}
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.

* Make sure **URL Protocol** is **http** not https.
* Syntax: **http\://\<Your\_Public\_IPv4\_Address>/index.html**
* Sample URL: **[http://52.87.50.168/\*\*\_\*\*index.html](http://52.87.50.168/**_**index.html)**\_
* **Note:** If the index.html page is not loading, try removing **s** from the link, it should be HTTP.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/Gcl5m9t6WaB6issH/images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/017.png?fit=max&auto=format&n=Gcl5m9t6WaB6issH&q=85&s=917b9cee39e859c58e295a174d7fe35a" alt="" width="1222" height="524" data-path="images/labs/introduction-to-amazon-elastic-compute-cloud-ec2/017.png" />

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

> ##### Do You Know?
>
> The **Amazon EC2 P4d instance** is the most powerful EC2 instance  type available, with eight NVIDIA A100 Tensor Core GPUs, 1.1 TB of NVMe storage, and 400 Gbps network bandwidth, making it ideal for large-scale machine learning and HPC workloads.

### Completion and Conclusion

1. You have successfully created and launched an Amazon EC2 instance
2. You have successfully logged into the EC2 instance using SSH
3. You have successfully installed an Apache server on the instance
4. You have successfully created a webpage and published it.
5. You have successfully validated the lab.

### End Lab

1. Sign out of AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End Lab** from your IP Lab Portal and wait till the process gets completed.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Launch an EC2 Instance** — Check whether an EC2 Instance is launched or not.
* **Validate EC2 Instance Type t2.micro** — Check whether the EC2 instance type is t2.micro.
* **Launch EC2 AMI type Amazon Linux** — Check whether the EC2 instance is launched using an Amazon AMI.

## Related help

* [FAQs and Troubleshooting](/aws-saa/support/faqs-and-troubleshooting)
* [SSH into EC2 Instance](/aws-saa/support/ssh-into-ec2-instance)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.