# Day 15:AWS Compute EC2

#### What is Amazon EC2?

Amazon EC2 (Elastic Compute Cloud) is a highly configurable virtual server service that offers resizable compute capacity. It allows users to quickly launch and manage servers, scale them up or down as needed, and choose from a variety of configurations. EC2 provides the flexibility to handle a wide range of computing tasks, from small web applications to large-scale enterprise solutions.

#### Key Features

* **Instance Types**: Choose from various instance types based on your needs.
    
* **Amazon Machine Images (AMIs)**: Select the operating system you prefer, such as Red Hat, Ubuntu, Microsoft, Amazon Linux, or SUSE.
    
* **Storage Options**: Attach storage volumes like Elastic Block Store (EBS) or Elastic File System (EFS), with options for SSD, HDD, and more.
    
* **Security and Networking**: Configure security groups, key pairs, IAM roles, and placement groups to manage access and network traffic.
    

#### EC2 Instance Families

EC2 instances are grouped into families based on their capabilities. Each family offers different combinations of CPU, memory, storage, and networking capacity to suit various use cases.

* **General Purpose**: Balances compute, memory, and networking resources. Suitable for web servers and code repositories.
    
    * Examples: A1, T2, T3, T3a, T4g, M4, M5, M5a, M5n, M6zn, M6g, M6i, Mac.
        
* **Compute Optimized**: Designed for compute-bound applications that benefit from high-performance processors. Ideal for scientific modeling and gaming servers.
    
    * Examples: C5, C4, C6g, C6gn.
        
* **Memory Optimized**: Provides fast performance for workloads that process large datasets in memory. Suitable for databases and in-memory processing.
    
    * Examples: R4, R5, R5a, R5n, X1, X1e.
        
* **Accelerated Computing**: Uses hardware accelerators or co-processors for specialized applications like machine learning and computational finance.
    
    * Examples: P2, P3, P4, G3, G4ad, G4dn, F1, Inf1, VT1.
        
* **Storage Optimized**: Offers high, sequential read and write access to large datasets on local storage. Best for data warehousing and NoSQL databases.
    
    * Examples: I3, I3en, D2, D3, D3en, H1.
        

#### EC2 Instance Types

An instance type defines the size and family of an EC2 instance. Sizes generally follow a pattern but can vary.

* **Common Sizes**: nano, micro, small, medium, large, xlarge, 2xlarge, 4xlarge, 8xlarge.
    
* **Exceptions**: Some instance sizes do not follow the typical pattern. For instance, `c6.metal` is a bare metal machine, and `c5.9xlarge` is not a power-of-2 size.
    

#### EC2 Pricing Models

EC2 offers several pricing models to fit different usage patterns:

* **On-Demand**: Pay-as-you-go pricing with no long-term commitment. Ideal for short-term, spiky, or unpredictable workloads. Charges are based on per-second or per-hour usage.
    
* **Spot Instances**: Provide up to 90% savings compared to On-Demand pricing by utilizing unused capacity. Suitable for flexible, low-cost applications that can handle interruptions.
    
* **Reserved Instances (RI)**: Offer up to 75% savings with a commitment to use EC2 instances over a 1- or 3-year term. RIs can be Standard (more cost-effective but less flexible) or Convertible (more flexible with slightly higher costs). Options include All Upfront, Partial Upfront, and No Upfront payments.
    
* **Dedicated Hosts**: Provide physical isolation for regulatory or licensing requirements. You can bring your own licenses and control the physical server attributes.
    
* **Savings Plans**: Provide flexibility across multiple AWS services with potential savings up to 72%. They include Compute Savings Plans and EC2 Instance Savings Plans.
    

#### EC2 Tenancy

EC2 offers three levels of tenancy:

* **Dedicated Host**: Provides physical isolation and control over hardware.
    
* **Dedicated Instance**: Runs on hardware dedicated to a single customer but may share with other instances from the same AWS organization.
    
* **Default**: Runs on shared hardware with other AWS customers.
