# Exploring Amazon EC2 Virtual Servers

Amazon EC2 (Elastic Compute Cloud) is **<mark>a web service that provides on-demand, scalable computing capacity in the Amazon Web Services (AWS) cloud</mark>**. It allows users to rent virtual machines, called "instances," to run their applications on AWS.

EC2 Types :

1. General purpose :
    
    Great for a diversity of workload such as web servers or code repositories.
    
    Balance between : Compute
    
    Memory
    
    Networking
    
    For Lab, We will be using the t2.micro which is a General Purpose EC2 instance.
    
2. Compute Optimized :
    
    Great for compute-intensive tasks that required high performance processors :
    
    Batch processing workloads
    
    Media transcoding
    
    High performance web servers
    
    High performance compute (HPC)
    
    Scientific modeling and machine learning
    
    Dedicated gaming server
    
3. Memory Optimized :
    
    Fast performance for workloads that process large data sets in memory
    
    Use cases : High performance, relational/non-relational database
    
    Distributed web scale cache stores
    
    In-memory database optimized for BI (business Intelligence)
    
    Applications performing real-time processing of big unstructured data
    
4. Storage Optimized :
    
    Great for storage-intensive tasks that require high, sequential read and write access to large data sets on local storage
    
    Use cases : High frequency online transaction processing (OLTP) systems
    
    Relational and NoSQL databases
    
    Cache for in-memory databases
    
    Data warehousing applications
    
    Distributed file system
    
5. Accelerated computing :
    
    specialized instances that include hardware accelerators like GPUs, FPGAs, or custom chips to handle demanding workloads more efficiently than standard EC2 instances.
    
    Use case : Deep learning training
    
    ML Inference
    
    Video rendering/streaming
    
    Custom hardware acceleration
    
    Data Analytics acceleration
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745383590787/e4b9c360-4766-4526-bcf5-659ddfc33454.webp align="center")
    

Introduction to security groups

* Security groups are the fundamental of network security in AWS.
    
* They control how traffic is allowed in to or out of our EC2 Instances.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745383540404/ecf0748e-147c-470b-a9ce-09beb5b76b3c.png align="center")
    
* Security groups only contain allow rules.
    
* Security groups rules can reference by IP or by security groups.
    
* Security groups are acting as a “firewall” on EC2 instances.
    
* They regulate :
    
    Access to ports
    
    Authorised IP ranges -IPv4 and IPv6.
    
    Control of inbound network (from network to the instance).
    
    Control of outbound network (from the instance to other).
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745384251060/62d0cbec-bec0-4a02-b4ce-eeca1cfba46f.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745388339409/f5e152db-f3c5-4d2d-8b0f-f2eacc78fc99.png align="center")

* Can be attached to multiple instances.
    
* Does live “outside” the EC2 if traffic is blocked the EC2 instance won’t se it.
    
* It’s good to maintain one separated security group for SSH access.
    
* All inbound traffic is blocked by default.
    
* All outbound traffic is authorised by default.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745388934216/0e346412-994c-4a6c-94ea-8e799be58ec9.webp align="center")

## **How to Create an EC2 Instance in AWS (Step-by-step)**

1. Log in to AWS Console.
    
2. Select the **Region.**
    
3. From **AWS Management Console**, Search **“EC2”**. (Navigate to the EC2 console).
    
4. Select **launch Instance** from the EC2 console dashboard.
    
5. **Name and tags** Give your instance a name. (Example : myfirstec2machine).
    
6. **Application and OS Images (Amazon Machine Image)**
    
    For windows : Windows Microsoft
    
    For Linux : Amazon Linux, Ubuntu, Red Hat, SUSE Linux, Debian. (Example : Amazon Linux)
    
7. Select **AMI** as per your requirements. (For Lab I am using free tier)
    
8. **Instance type** select as per your requirements. (free tier t2,t3 micro )
    
9. **Key pair (login)** Select an existing key pair or create a new one.
    
    For new key pair :
    
    Click **Create new key pair**
    
    Give **Key pair name** ( EX : myfirstec2machine)
    
    **Key pair type** Select **RSA**
    
    **Private key file format** For windows machine :
    
    .pem (SSH access)
    
    .ppk (putty access)
    
    **Create new key pair**
    
10. **Network settings** Default settings are okay for testing.
    
    * Make sure **SSH (port 22)** is allowed if it's a Linux instance.
        
    * For web apps, allow **HTTP (80)** and **HTTPS (443)**.
        
11. **Configure storage** Default: 8 GB
    
    (You can adjust size and type based on workload).
    
12. Review and **Launch instance.**
    
    Wait a few seconds.
    

After that

How to connect through RDP Client

1. Select **connect.**
    
2. Select **RDP Client**.
    
3. Download remote desktop file.
    
4. Select **get password**. Upload **private key file** and **Decrypt password.**
    
5. Copy **password** and cancel.
    

How to login machine

1. Select Downloaded remote desktop file (EX : myfirstec2machine.rdp) After that Click connect paste the password you copied earlier and click yes. (1st way to connect)
    
2. Select Remote desktop connection on your machine give public IP and password that you copied Click connect Click yes.
    

How to connect through putty.

1. Copy Public IP
    
2. In your machine Download Putty and Open putty.
    
3. Host name (or IP address) paste copied IP.
    
4. Select path SSH/Auth/Credentials.
    
5. Private key file for authentication Select Browse.
    
6. Upload Private key click open click Accept.
    

---

> Ubuntu login as : ubuntu
> 
> Amazon Linux machine login as : ec2-user

Ports uses :

* 22 = SSH (Secure shell) - Log into a Linux instance.
    
* 21 = FTP (File Transfer Protocol) - Upload files into a file share.
    
* 22 = SFTP (Secure File Transfer pro Protocol) - Upload files using SSH.
    
* 80 = HTTP - Access unsecured Websites.
    
* 443 = HTTPS - Access secured Websites.
    
* 3389 = RDP - (Remote desktop Protocol) Log into a window instance.
    

Here are a few common issues people run into :

* **Permission denied (public key/password)** – Authentication problems.
    
* **Connection timed out** – The server isn't reachable or port 22 is blocked.
    
* **Host key verification failed** – The server's identity changed or the known hosts file has conflicts.
    
* **"Could not resolve hostname"** – Typo in the hostname or wrong domain/IP.
    
* **"Connection refused"** – SSH server might not be running or listening on the expected port.
    

**Conclusion :**

Amazon EC2 provides a versatile and scalable solution for deploying virtual servers in the cloud. With a variety of instance types tailored to different workloads, users can optimize their applications for performance, cost, and efficiency. The integration of security groups ensures robust network security, allowing for controlled access and data protection. By following the step-by-step guide to creating and connecting to an EC2 instance, users can effectively leverage AWS's powerful infrastructure to meet their computing needs. Whether for web hosting, data processing, or specialized computing tasks, Amazon EC2 offers the flexibility and resources necessary to support a wide range of applications.
