Module Objective: Describe Amazon EC2 and its purchasing options, explain how AWS scales compute automatically, and compare virtual machine, container, and serverless approaches to running workloads.

Builds on Modules 3 and 5 — compute resources are placed into Availability Zones and Amazon VPC subnets already covered.

Amazon EC2 Fundamentals

Amazon Elastic Compute Cloud (EC2) provides resizable virtual servers, called instances, in the cloud. It's the core IaaS compute offering on AWS: the customer manages the guest operating system and everything above it, while AWS manages the underlying physical hardware and virtualization layer.

ConceptWhat It Is
InstanceA virtual server running in a specific Availability Zone, launched from an AMI
ElasticInstances can be launched, resized, or terminated on demand as capacity needs change
Billing granularityMost instances are billed per second, with a 60-second minimum
🔵 Why It Matters EC2 is usually the first compute service introduced because it maps most directly onto a traditional physical or virtual server — everything else in this module trades some of that control for reduced operational overhead.

EC2 Instance Types

EC2 instance types are grouped into families optimized for different resource ratios. A type name like m5.large encodes the family (m5) and the size (large).

FamilyOptimized ForExample Use Case
General purposeBalanced compute, memory, and networkingWeb servers, small-to-medium databases
Compute optimizedHigh-performance processorsBatch processing, media transcoding, gaming servers
Memory optimizedFast performance for large in-memory datasetsIn-memory databases, real-time big data analytics
Storage optimizedHigh, sequential read/write access to large local datasetsData warehousing, distributed file systems
Accelerated computingHardware accelerators such as GPUsMachine learning training, graphics rendering
✅ Tip — Right-Size, Don't Guess Choosing an instance family is one of the clearest examples of the "no more guessing capacity" benefit from Module 2 — instances can be resized or changed as actual workload behavior becomes clear, rather than committing upfront.

EC2 Purchasing Options

EC2 offers several purchasing models, each trading flexibility for discount, echoing the "save when you reserve" and "pay-as-you-go" pricing models from Module 2.

OptionCommitmentBest For
On-DemandNoneShort-term, spiky, or unpredictable workloads
Reserved Instances1- or 3-year termSteady-state workloads with predictable usage
Savings Plans1- or 3-year spending commitmentPredictable usage, with more flexibility across instance families than Reserved Instances
Spot InstancesNone, but can be reclaimed by AWS with short noticeFault-tolerant, flexible workloads such as batch jobs, at steep discounts
Dedicated HostsVariesWorkloads with licensing or compliance needs requiring a physical server dedicated to one customer
⚠️ Warning — Spot Instances Can Be Interrupted AWS can reclaim a Spot Instance with a two-minute warning whenever it needs the capacity back. Spot is a strong fit for stateless or checkpointed work, but a poor fit for anything that can't tolerate sudden termination.

AMIs and the Instance Lifecycle

Every EC2 instance is launched from an Amazon Machine Image (AMI) — a template containing the operating system and any pre-installed software needed. AMIs can come from AWS, the AWS Marketplace, the community, or be created by a customer from an existing instance.

StateWhat It Means
RunningThe instance is active and billed for compute time
StoppedThe instance is shut down; no compute charges, but attached storage still incurs cost
TerminatedThe instance is permanently deleted, along with its root storage by default
🔵 Note Stopping an instance is not the same as terminating it — a stopped instance can be started again later with its configuration intact, while a terminated instance is gone for good.

Scaling Compute: Auto Scaling and Elastic Beanstalk

Rather than manually launching and terminating instances, AWS offers services that scale compute automatically in response to demand.

ServiceWhat It Does
Amazon EC2 Auto ScalingAutomatically adds or removes instances in an Auto Scaling group based on demand, health checks, or a schedule, keeping capacity matched to load
AWS Elastic BeanstalkA PaaS offering: upload application code and Elastic Beanstalk automatically handles provisioning, load balancing, scaling, and health monitoring
✅ Tip — Auto Scaling Pairs With Load Balancing Auto Scaling groups are commonly used together with the Elastic Load Balancing service from Module 5 — the load balancer distributes traffic across whatever instances the Auto Scaling group currently has running.

Container Services

Containers package an application with its dependencies into a portable, lightweight unit. AWS offers container orchestration services that manage where and how containers run.

ServiceWhat It Is
Amazon Elastic Container Service (ECS)AWS's own container orchestration service for running and scaling containerized applications
Amazon Elastic Kubernetes Service (EKS)A managed service for running the open-source Kubernetes orchestration platform on AWS
AWS FargateA serverless compute engine for containers, usable with either ECS or EKS, removing the need to provision or manage the underlying servers
🔵 Note ECS and EKS answer "how are my containers orchestrated?" while Fargate answers a separate question — "what runs the servers underneath them?" Either orchestrator can run on Fargate or on customer-managed EC2 instances.

Serverless Compute: AWS Lambda

AWS Lambda runs code in response to events without provisioning or managing any servers. Customers upload code, and Lambda handles capacity, scaling, and availability automatically.

PropertyDetail
Trigger-basedRuns in response to events — an API call, a file upload to Amazon S3, a scheduled time, and more
BillingCharged based on the number of requests and the compute time actually consumed, down to the millisecond
Execution limitEach invocation has a maximum runtime, making Lambda best suited to short-lived tasks
✅ Tip — "Serverless" Means No Idle Cost Unlike an EC2 instance, which is billed while running whether or not it's doing useful work, Lambda has no charge at all when it isn't actively executing — a direct example of the "trade CapEx for OpEx" and pay-as-you-go principles from Module 2.

Choosing the Right Compute Service

AWS compute options sit on a spectrum from maximum control to maximum abstraction. The right choice depends on how much operational overhead a team wants to own versus hand off to AWS.

NeedLikely Fit
Full control over the OS and runtimeAmazon EC2
Deploy application code without managing infrastructureAWS Elastic Beanstalk
Portable, consistent environments across dev/test/prodContainers via ECS or EKS
Short-lived, event-driven functionsAWS Lambda
Containers without managing serversAWS Fargate
🔵 Note These options aren't mutually exclusive — many real architectures combine several, such as Lambda for lightweight event processing alongside an EC2- or ECS-based application handling the core workload.

Key Terms for Module 6

Amazon EC2
AWS's IaaS compute service, providing resizable virtual server instances
instance type
A specific combination of CPU, memory, storage, and networking capacity for an EC2 instance
On-Demand Instance
An EC2 purchasing option with no commitment, billed for actual usage
Spot Instance
A deeply discounted EC2 purchasing option that AWS can reclaim with short notice
Amazon Machine Image (AMI)
A template containing the OS and software used to launch an EC2 instance
Amazon EC2 Auto Scaling
Automatically adds or removes EC2 instances in a group based on demand or a schedule
AWS Elastic Beanstalk
A PaaS offering that automatically provisions and manages infrastructure for deployed application code
container
A lightweight, portable package of an application and its dependencies
AWS Fargate
A serverless compute engine for containers, usable with ECS or EKS
AWS Lambda
A serverless compute service that runs code in response to events without provisioning servers

Review Questions

  1. Under the shared responsibility model, what does AWS manage for an Amazon EC2 instance, and what does the customer manage?
  2. Which EC2 instance family would best fit a machine learning training workload, and why?
  3. Why might a workload use Spot Instances for part of its capacity and On-Demand or Reserved Instances for the rest?
  4. What is the difference between stopping and terminating an EC2 instance?
  5. How do Amazon EC2 Auto Scaling and Elastic Load Balancing work together to support a highly available application?
  6. What is the relationship between Amazon ECS, Amazon EKS, and AWS Fargate?
  7. Why is AWS Lambda often described as having "no idle cost," and how does that compare to billing for an EC2 instance?