Skip to the content.

EC2: Virtual Machines

What is Amazon EC2?

EC2 Sizing & Configuration Options

EC2 User Data

EC2 Instance Types - Overview

Amazon EC2 offers a variety of instance types, each designed to meet specific application requirements.(https://aws.amazon.com/ec2/instance-types/)

General Purpose Instances

Instance Type vCPUs Memory (GiB) Network Performance Storage
t4g.micro 2 1 Up to 5 Gigabit EBS only
t3.micro 2 1 Up to 5 Gigabit EBS only
m5.large 2 8 Up to 10 Gigabit EBS only
m5.xlarge 4 16 Up to 10 Gigabit EBS only

Compute Optimized Instances

Instance Type vCPUs Memory (GiB) Network Performance Storage
c5.large 2 4 Up to 10 Gigabit EBS only
c5.xlarge 4 8 Up to 10 Gigabit EBS only
c5.2xlarge 8 16 Up to 10 Gigabit EBS only
c5n.9xlarge 36 96 10 Gigabit EBS only

Memory Optimized Instances

Instance Type vCPUs Memory (GiB) Network Performance Storage
r5.large 2 16 Up to 10 Gigabit EBS only
r5.xlarge 4 32 Up to 10 Gigabit EBS only
r5.4xlarge 16 128 Up to 10 Gigabit EBS only
r5b.12xlarge 48 384 10 Gigabit EBS only

Storage Optimized Instances

Instance Type vCPUs Memory (GiB) Network Performance Storage
i3.large 2 15 Up to 10 Gigabit 1 x 475 GB NVMe SSD
i3.xlarge 4 30 Up to 10 Gigabit 1 x 950 GB NVMe SSD
i3.2xlarge 8 61 Up to 10 Gigabit 1 x 1.9 TB NVMe SSD
d2.8xlarge 36 244 Up to 10 Gigabit 12 x 2 TB HDD

EC2 Instance Types: Example

Here’s a quick overview of some example instance types in each category, along with their characteristics:

Instance Type vCPUs Memory (GiB) Storage Use Case
t3.micro 2 1 EBS only General-purpose applications with burstable performance; suitable for low-traffic web servers or development environments.
c5.large 2 4 EBS only Compute-intensive applications like gaming, web servers, and machine learning inference.
m5.xlarge 4 16 EBS only Balanced workloads, such as small databases and caching fleets. Ideal for web applications.
r5.xlarge 4 32 EBS only Memory-intensive applications such as databases, in-memory caches, and analytics workloads.
i3.2xlarge 8 61 1 x 2.5 TB NVMe SSD Storage-intensive applications like NoSQL databases, data warehousing, and big data analytics.
p3.2xlarge 8 61 EBS only GPU-accelerated computing for machine learning, high-performance computing (HPC), and graphics-intensive applications.

t2.micro is part of the AWS free tier (up to 750 hours per month)

Introduction to Security Groups

Common Use Cases

Deeper Dive

Security Groups Diagram

Security Groups Diagram

Examples of Security Group Rules

Rule Type Protocol Port Range Source/Destination
Inbound Rule TCP 22 203.0.113.0/24 (SSH Access)
Inbound Rule TCP 80 0.0.0.0/0 (HTTP Access)
Outbound Rule All Traffic All 0.0.0.0/0

Good to Know

Classic Ports to Know

Port Number Protocol Service Description
20 TCP FTP (Data Transfer) Used for transferring files over FTP.
21 TCP FTP (Control) Used for controlling file transfer sessions.
22 TCP SSH Secure Shell for secure logins and command execution.
80 TCP HTTP Hypertext Transfer Protocol for web traffic.
443 TCP HTTPS Secure HTTP for secure web traffic.
3389 TCP RDP Used for Remote Desktop Protocol, allowing users to connect to and control remote Windows machines.

EC2 Instance Launch Types

On Demand Instance

Reserved Instances

Savings Plans

Spot Instances

Dedicated Hosts

Dedicated Instances

Capacity Reservations

EC2 Instance Launch Types Comparison

Launch Type Cost Structure Payment Options Commitment Use Case Flexibility
On-Demand Instances - Linux/Windows: per second after the first minute
- Other OS: billed per hour
No upfront payment No long-term commitment Short-term and unpredictable workloads High flexibility; can start/stop anytime
Reserved Instances Up to 72% discount compared to On-Demand - No Upfront
- Partial Upfront
- All Upfront
1 year or 3 years Steady-state applications (e.g., databases) Reserved capacity in a specific region or AZ
Savings Plans Up to 72% discount based on long-term usage Commit to a certain usage amount 1 year or 3 years Applications with predictable usage patterns Flexible across instance size, OS, and tenancy
Spot Instances Discount up to 90% compared to On-Demand Pay the Spot price No commitment required Cost-sensitive, resilient workloads (e.g., batch jobs) Instances can be terminated anytime if spot price exceeds your max price
Dedicated Hosts Most expensive; pay per second for active host - On-Demand
- Reserved (1 or 3 years)
Long-term commitment possible Compliance-heavy applications or complex licensing models Full control over server; ideal for BYOL scenarios
Dedicated Instances Higher than shared instances; not the most expensive On-Demand pricing No long-term commitment Workloads needing dedicated hardware but can share resources Limited control over instance placement
Capacity Reservations Billed at On-Demand rates regardless of instance running No upfront payment No time commitment Ensures EC2 capacity availability in a specific AZ Can create/cancel anytime; no discounts on billing

Which purchasing option is right for my use case?

Price Comparison Example – m4.large – us-east-1

Launch Type Hourly Price Monthly Price (Approx.) Notes
On-Demand Instance $0.096 per hour $69.12 Pay-as-you-go pricing. Ideal for short-term usage.
Reserved Instances $0.054 per hour (1-year term) $39.24 Commit to one year for a significant discount.
Savings Plans $0.058 per hour (1-year term) $41.76 Flexible savings plan applicable to any instance type.
Spot Instances $0.028 per hour (varies with demand) $20.16 Pricing varies; can be interrupted. Best for flexible workloads.
Dedicated Hosts $0.12 per hour (per host) $86.40 Dedicated physical server; pricing per host.
Dedicated Instances $0.096 per hour $69.12 Similar to on-demand but on dedicated hardware.
Capacity Reservations $0.096 per hour $69.12 Reserved capacity at on-demand pricing.

Shared Responsibility Model for EC2

Responsibility AWS Responsibilities User Responsibilities
Infrastructure Security The security of the underlying infrastructure, including hardware, software, networking, and facilities. Securing the EC2 instances, including operating systems and applications.
Physical Security Ensures physical security of data centers where EC2 instances run. N/A
Network Security Implements security measures for the network, including firewalls and DDoS protection. Configuring security groups, network ACLs, and VPC settings.
Data Protection Provides encryption options for data at rest and in transit. Managing data encryption and access control.
Access Management Offers IAM services to manage access to AWS resources. Configuring IAM users, roles, and policies for access management.
Compliance Complies with various compliance standards and certifications for infrastructure. Compliance related to the applications and data hosted on EC2 instances.
Patch Management Provides a secure and up-to-date infrastructure. Applying patches and updates to the operating system and applications.

EC2 Section – Summary