Amazon EC2 Guide: Launch, Configure & Connect Virtual Servers
Learn Amazon EC2 from scratch. Covers instance types, AMIs, key pairs, security groups, EBS volumes, Elastic IPs, pricing models, and how to launch your first EC2 instance.

Amazon Elastic Compute Cloud (EC2) is the core compute service in AWS. It provides resizable virtual machines — called instances — that you can launch, configure, and terminate on demand. EC2 is the foundation of most AWS architectures and accounts for the largest portion of the SAA-C03 exam.
What Is an EC2 Instance?
An EC2 instance is a virtual machine running in an AWS data centre. You choose the operating system (via an AMI), the instance type (CPU, memory, network), the storage (EBS volumes), the network configuration (VPC, subnet, security groups), and the IAM role (for permissions).
Instances run in a specific Availability Zone within a Region. You can SSH into them, install software, and use them as servers, build systems, database hosts, or anything else a Linux/Windows server can do.
Amazon Machine Images (AMIs)
An AMI is a pre-configured OS image used to launch instances. It includes the root OS, pre-installed software (optional), configuration settings, and EBS snapshot(s) for the root volume.
AMI Sources
| Source | Description |
|---|---|
| AWS-provided | Amazon Linux, Ubuntu, Windows — official, updated, free |
| AWS Marketplace | Third-party software pre-installed (costs may apply) |
| Community AMIs | Public AMIs shared by others — use with caution |
| Your own AMIs | Custom AMIs you create from your instances (for golden images) |
AMIs are region-specific — an AMI in us-east-1 cannot be directly used in eu-west-1 (but can be copied across regions).
Instance Types
AWS offers hundreds of instance types organised into families. The naming convention is:
c6g.2xlarge
│ │ └── Size (nano, micro, small, medium, large, xlarge, 2xlarge, ...)
│ └── Generation (6 = 6th generation)
└── Family (c = compute optimised)Instance Families
| Family | Optimised For | Use Cases |
|---|---|---|
| M (General Purpose) | Balanced CPU/memory | Web servers, app servers |
| C (Compute) | High CPU | Video encoding, HPC, gaming |
| R (Memory) | High RAM | In-memory databases, real-time analytics |
| I (Storage) | High I/O, NVMe SSD | Databases, data warehousing |
| G/P (GPU) | Graphics/ML | Machine learning training, rendering |
| T (Burstable) | Low baseline + burst | Dev/test, low-traffic sites |
For the exam: Know that T-series instances have CPU credits. When credits run out, CPU is throttled to the baseline rate. t3.micro is free-tier eligible.
EC2 Pricing Models
This is one of the most exam-tested topics. Choose the wrong pricing model and you either overpay or have no capacity when you need it.
| Model | Discount vs On-Demand | Commitment | Best For |
|---|---|---|---|
| On-Demand | None | None | Unpredictable workloads, short-term |
| Reserved (1yr) | ~40% | 1 year | Steady-state workloads |
| Reserved (3yr) | ~60%+ | 3 years | Long-term predictable workloads |
| Savings Plans | Similar to Reserved | 1 or 3 years | Flexible — covers EC2, Lambda, Fargate |
| Spot Instances | Up to 90% | None | Fault-tolerant, interruptible workloads |
| Dedicated Hosts | — | On-Demand or Reserved | Licence compliance, regulatory requirements |
Spot Instances — Key Details
Spot instances use spare AWS capacity at steep discounts. AWS can reclaim them with a 2-minute warning if the spot price exceeds your bid or capacity is needed.
Design Spot workloads to be stateless and interruptible: big data processing, video rendering, CI/CD pipelines, ML training. Never run a primary database on Spot.
Key Pairs
To SSH into a Linux EC2 instance, you use a key pair: AWS stores the public key on the instance, and you keep the private key (.pem file) — never share it.
# Set correct permissions on the private key
chmod 400 my-key.pem
# SSH into the instance
ssh -i my-key.pem ec2-user@<public-ip>
# For Ubuntu: ubuntu@<public-ip>
# For Amazon Linux: ec2-user@<public-ip>If you lose the private key, you cannot recover it. You'll need to create a new key pair and update the instance.
Security Groups
A Security Group is a stateful virtual firewall that controls inbound and outbound traffic for an instance.
Security Group: web-server-sg
Inbound Rules:
Type: SSH, Port: 22, Source: My IP (203.0.113.5/32)
Type: HTTP, Port: 80, Source: 0.0.0.0/0
Type: HTTPS,Port: 443, Source: 0.0.0.0/0
Outbound Rules:
Type: All, Port: All, Destination: 0.0.0.0/0 (default — allow all)Key properties: Stateful (if inbound traffic is allowed, the response is automatically allowed outbound), Allow-only (security groups can only Allow — use NACLs for deny rules), Multiple per instance (up to 5 security groups), and you can Reference other SGs to allow traffic between tiers.
EBS Volumes
Elastic Block Store (EBS) provides persistent block storage for EC2 instances.
EBS Volume Types
| Type | Use Case | Max IOPS |
|---|---|---|
| gp3 (General Purpose SSD) | Most workloads, default | 16,000 IOPS |
| gp2 (General Purpose SSD) | Older default | 16,000 IOPS |
| io2 Block Express | Mission-critical databases | 256,000 IOPS |
| st1 (Throughput HDD) | Big data, log processing | 500 MB/s throughput |
| sc1 (Cold HDD) | Infrequently accessed, lowest cost | 250 MB/s throughput |
EBS volumes are AZ-specific — a volume in us-east-1a cannot be directly attached to an instance in us-east-1b. Take a snapshot (backed by S3) to move data between AZs or regions.
Elastic IPs
By default, EC2 instances get a dynamic public IP that changes every time they stop and start. An Elastic IP is a static public IPv4 address you can allocate and associate with an instance permanently.
# Allocate an Elastic IP (via CLI)
aws ec2 allocate-address --domain vpc
# Associate with an instance
aws ec2 associate-address \
--instance-id i-abc123 \
--allocation-id eipalloc-xyz456Elastic IPs are free while associated with a running instance. You're charged per hour when they're allocated but NOT associated — release unused EIPs to avoid charges.
Launching Your First EC2 Instance
- Open the EC2 Console → Launch Instance
- Name:
my-web-server - AMI: Amazon Linux 2023 (free tier eligible)
- Instance type: t3.micro (free tier eligible)
- Key pair: Create new → download
.pem - Network: Default VPC, public subnet
- Security group: Allow SSH (port 22, your IP) + HTTP (port 80, anywhere)
- Storage: 8 GB gp3 (default)
- Launch
Connect:
chmod 400 my-key.pem
ssh -i my-key.pem ec2-user@<public-ip>
# Install a web server
sudo dnf install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
echo "<h1>Hello from EC2</h1>" | sudo tee /var/www/html/index.htmlVisit http://<public-ip> in your browser.
Previous: Lesson 3 — AWS IAM | Next: Lesson 5 — Amazon S3
Part of the AWS Cloud Fundamentals course.
External references:
