AWSDOP-C02
On this page
Beginner-friendly overview

EC2

EC2 gives you virtual servers in AWS's data centers. You rent compute capacity by the second โ€” CPU, RAM, and storage โ€” without buying or maintaining any physical hardware. Within minutes you can have a Linux or Windows server running anywhere in the world.

Why EC2 Exists

Before cloud computing, running a server meant buying hardware, racking it in a data center, waiting weeks for delivery, and paying for it whether you used it or not. EC2 flipped that model. You launch a server when you need it, choose exactly how much CPU and memory it gets, and stop paying the moment you shut it down. For workloads that need a full server environment โ€” custom software, persistent processes, GPU compute, legacy apps โ€” EC2 is the right tool.

How It Works

When you launch an EC2 instance, you make three key choices:

AMI (Amazon Machine Image) โ€” the pre-built template for your server's operating system and software. AWS provides standard AMIs for Amazon Linux, Ubuntu, Windows Server, and others. You can also create your own AMI from an existing instance to bake in your application.

Instance type โ€” the hardware configuration. Instance types are grouped by use case: general purpose (t3, m6i), compute-optimized (c6i), memory-optimized (r6i), storage-optimized (i3), and GPU (p4, g5). The type determines how many vCPUs, how much RAM, and what network bandwidth you get.

VPC and subnet โ€” where in your private network the instance lives. An instance in a public subnet can have a public IP and be reached from the internet. One in a private subnet can only be reached from within your network.

Launching an instance = three choices: what software, what hardware, where AMI what's on the disk OS + software template Amazon Linux ยท your golden AMI Instance type how big the hardware vCPU ยท RAM ยท network t3.micro โ€ฆ p4 GPU monster VPC + subnet where on the network public = internet-reachable private = internal only Running EC2 instance billed per second while running ยท stop it, stop paying for compute Same three questions every launch: Which image? What size? Which network?

Connecting to Your Instance

For Linux instances you connect via SSH using a key pair. For Windows you use RDP. AWS also offers Session Manager (part of Systems Manager), which lets you open a shell in the browser with no open ports at all โ€” a more secure option for production servers.

Storage

Every EC2 instance gets a root volume for its operating system. You can attach additional EBS (Elastic Block Store) volumes for persistent data โ€” these survive instance restarts and can be snapshotted. For temporary scratch space, instance store volumes offer very fast local disk but data is lost when the instance stops.

Two kinds of disk, one rule:
EBS = a USB drive โ€” attached over the network, survives stop/start, can be snapshotted, unplugged, and moved.
Instance store = a whiteboard bolted to the rack โ€” blazing fast because it's physically local, but wiped the moment the instance stops or terminates.

The Bigger Picture

EC2 is the building block underneath many higher-level services. ECS runs containers on EC2, Elastic Beanstalk manages EC2 instances on your behalf, and RDS runs database servers on EC2 behind the scenes. Understanding EC2 helps you understand all of them.