journalaws / ec2

*Introduction to Amazon EC2

May 22, 2026·7 min read
Architecture diagram for Introduction to Amazon EC2

What Is EC2?

Amazon EC2 (Elastic Compute Cloud) is AWS's service for renting virtual servers in the cloud. Each virtual server is called an instance. Instead of buying, setting up, and maintaining physical hardware, you launch an instance in a few minutes, choose its operating system and size, use it for as long as you need, and pay only for the time it runs.

The "elastic" part means capacity can grow or shrink with demand. You can launch one instance or hundreds, resize an instance, or shut instances down when they're no longer needed.

EC2 is an example of Infrastructure as a Service (IaaS). AWS manages the physical hardware, data centers, and networking underneath. You manage everything on the instance itself, including the operating system, updates, installed software, and security settings.


Core Building Blocks

Instances

An instance is a single virtual server. It has its own CPU, memory, storage, and network connection, and it runs a full operating system like Amazon Linux, Ubuntu, or Windows Server.

AMIs (Amazon Machine Images)

An AMI is the template an instance is launched from. It contains the operating system and any pre-installed software and configuration. AWS provides ready-made AMIs, the AWS Marketplace offers third-party ones, and you can create custom AMIs from your own configured instances to launch identical copies later.

Instance types

The instance type decides how much CPU, memory, storage, and network performance an instance gets. Instance type names follow a pattern:

t3.micro
│││  └── size (nano, micro, small, medium, large, xlarge, 2xlarge, …)
││└──── generation (higher is newer)
│└───── (optional extra letters for features, e.g. "g" for Graviton processors)
└────── family

Common families:

FamilyOptimized forExample uses
T (e.g. t3)Burstable general purpose: low baseline CPU that can burst when neededSmall websites, dev and test servers, labs
M (e.g. m7i)Balanced general purpose: even mix of CPU and memoryApplication servers, mid-size databases
C (e.g. c7i)Compute: high CPU relative to memoryBatch processing, video encoding, game servers
R (e.g. r7i)Memory: large amounts of RAMIn-memory caches, large databases, analytics
G / PAccelerated computing: GPUsMachine learning, graphics rendering
I (e.g. i4i)Storage: very fast local disksHigh-performance databases, data warehousing

Key pairs

A key pair is how you prove your identity when connecting. AWS keeps the public key on the instance, and you keep the private key (a .pem or .ppk file). Linux instances use it to log in over SSH. Windows instances use it to decrypt the initial Administrator password for RDP.

Security groups

A security group is a virtual firewall attached to an instance. Inbound rules control which traffic can reach the instance, such as SSH on port 22, RDP on port 3389, or HTTP on port 80. By default, all inbound traffic is blocked and all outbound traffic is allowed.

Storage

TypeWhat it isSurvives stop/start?
EBS volumeNetwork-attached virtual disk. The root volume holding the OS is usually EBS. Extra volumes can be attached, resized, and backed up with snapshots.Yes
Instance storeDisks physically attached to the host machine, available on some instance types. Very fast, but temporary.No, data is lost when the instance stops or terminates
EFSShared network file system that many Linux instances can mount at onceYes, it's independent of any instance

Networking

Every instance launches into a subnet inside a VPC, which places it in a specific Availability Zone. Each instance gets a private IP for communication inside the VPC, and optionally a public IP for internet access. A public IP changes if the instance is stopped and started. An Elastic IP is a static public IP that stays the same.

User data

User data is a script you can provide at launch that runs automatically the first time the instance boots. It's commonly used to install software, apply updates, or configure the server without logging in manually.


Instance Lifecycle

StateWhat's happeningBilled for compute?
PendingThe instance is starting upNo
RunningThe instance is on and usableYes
StoppingThe instance is shutting downNo (except when hibernating)
StoppedThe instance is off, but its EBS volumes are keptNo, but EBS storage is still billed
TerminatedThe instance is permanently deletedNo

Stopping is like turning a computer off: it can be started again later. Terminating is permanent. By default, the root EBS volume is deleted on termination, but additional volumes attached after launch are not.


Pricing Models

ModelHow it worksBest for
On-DemandPay per second (Linux) or per hour, with no commitmentShort-term, unpredictable, or new workloads; labs and testing
Savings PlansCommit to a set amount of compute spending per hour for 1 or 3 years in exchange for a large discountSteady, long-running workloads
Reserved InstancesCommit to a specific instance type in a region for 1 or 3 years in exchange for a discountPredictable workloads that won't change instance type
Spot InstancesUse AWS's spare capacity at a steep discount, but AWS can reclaim the instance with a 2-minute warningFlexible, interruption-tolerant work like batch jobs and data processing
Dedicated Hosts / InstancesRun on hardware reserved only for your accountLicensing requirements or compliance rules that forbid shared hardware

Besides the instance itself, other things add to the bill: EBS volumes and snapshots, public IPv4 addresses, and data transferred out to the internet.


Common Use Cases

Hosting websites and web applications

EC2 can run web servers like Apache, Nginx, or IIS to host websites, APIs, and full web applications. For high availability, instances can run in several Availability Zones behind a load balancer.

Application and backend servers

Business applications, internal tools, and backend services can run on EC2, often in private subnets where they're reachable only from other parts of the system and not directly from the internet.

Databases

Databases like MySQL, PostgreSQL, or MongoDB can be installed directly on EC2 when full control over the configuration is needed. AWS also offers managed database services such as Amazon RDS, which take care of backups, patching, and failover.

Development and testing environments

Developers can quickly launch servers that match production, test changes, and terminate them afterward, paying only for the hours used.

Batch processing and data analysis

Large jobs like processing logs, transforming data, or running reports can be spread across many instances, often using Spot Instances to cut costs.

Machine learning and high-performance computing

GPU instances train and run machine learning models, and compute-optimized instances handle scientific simulations, financial modeling, and rendering.

Game servers

Multiplayer game servers can run on EC2 in regions close to players to reduce lag, scaling up during busy times and down when traffic drops.

Lift-and-shift migrations

Companies moving to the cloud often start by moving their existing on-premises servers onto EC2 with few or no changes, since EC2 instances behave much like traditional servers.

Remote desktops and Windows workloads

Windows Server instances can host Windows-only applications and be accessed over RDP, as in a remote desktop setup.


Scaling and High Availability

  • Auto Scaling groups automatically add instances when demand rises and remove them when it falls, and replace instances that fail health checks.
  • Elastic Load Balancing spreads incoming traffic across multiple instances, so no single instance is overloaded and one failure doesn't take the application down.
  • Running instances in multiple Availability Zones protects against a problem in a single data center.

When EC2 Might Not Be the Best Fit

Because EC2 gives full control over the server, it also comes with the responsibility of managing it. Other AWS services can be simpler for some workloads:

NeedAlternative
Run short pieces of code in response to events, without managing serversAWS Lambda
Run containerized applicationsAmazon ECS or Amazon EKS (which can run on EC2 or on AWS Fargate)
Deploy a web application without configuring serversAWS Elastic Beanstalk
Run a relational database without managing itAmazon RDS or Amazon Aurora
Host a static websiteAmazon S3 with Amazon CloudFront

Key Takeaways

  • EC2 provides virtual servers that can be launched in minutes and paid for only while they run.
  • An instance is defined by its AMI (what's installed), instance type (how powerful it is), storage, network placement, and security group (what traffic it allows).
  • Stopping an instance pauses compute charges but keeps its storage, while terminating deletes it permanently.
  • Choosing the right pricing model can significantly lower costs for long-running or flexible workloads.
  • EC2 is the most flexible way to run workloads on AWS, which makes it a good fit when full control over the server is needed.