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.
| Concept | What It Is |
|---|---|
| Instance | A virtual server running in a specific Availability Zone, launched from an AMI |
| Elastic | Instances can be launched, resized, or terminated on demand as capacity needs change |
| Billing granularity | Most instances are billed per second, with a 60-second minimum |
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).
| Family | Optimized For | Example Use Case |
|---|---|---|
| General purpose | Balanced compute, memory, and networking | Web servers, small-to-medium databases |
| Compute optimized | High-performance processors | Batch processing, media transcoding, gaming servers |
| Memory optimized | Fast performance for large in-memory datasets | In-memory databases, real-time big data analytics |
| Storage optimized | High, sequential read/write access to large local datasets | Data warehousing, distributed file systems |
| Accelerated computing | Hardware accelerators such as GPUs | Machine learning training, graphics rendering |
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.
| Option | Commitment | Best For |
|---|---|---|
| On-Demand | None | Short-term, spiky, or unpredictable workloads |
| Reserved Instances | 1- or 3-year term | Steady-state workloads with predictable usage |
| Savings Plans | 1- or 3-year spending commitment | Predictable usage, with more flexibility across instance families than Reserved Instances |
| Spot Instances | None, but can be reclaimed by AWS with short notice | Fault-tolerant, flexible workloads such as batch jobs, at steep discounts |
| Dedicated Hosts | Varies | Workloads with licensing or compliance needs requiring a physical server dedicated to one customer |
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.
| State | What It Means |
|---|---|
| Running | The instance is active and billed for compute time |
| Stopped | The instance is shut down; no compute charges, but attached storage still incurs cost |
| Terminated | The instance is permanently deleted, along with its root storage by default |
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.
| Service | What It Does |
|---|---|
| Amazon EC2 Auto Scaling | Automatically adds or removes instances in an Auto Scaling group based on demand, health checks, or a schedule, keeping capacity matched to load |
| AWS Elastic Beanstalk | A PaaS offering: upload application code and Elastic Beanstalk automatically handles provisioning, load balancing, scaling, and health monitoring |
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.
| Service | What 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 Fargate | A serverless compute engine for containers, usable with either ECS or EKS, removing the need to provision or manage the underlying servers |
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.
| Property | Detail |
|---|---|
| Trigger-based | Runs in response to events — an API call, a file upload to Amazon S3, a scheduled time, and more |
| Billing | Charged based on the number of requests and the compute time actually consumed, down to the millisecond |
| Execution limit | Each invocation has a maximum runtime, making Lambda best suited to short-lived tasks |
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.
| Need | Likely Fit |
|---|---|
| Full control over the OS and runtime | Amazon EC2 |
| Deploy application code without managing infrastructure | AWS Elastic Beanstalk |
| Portable, consistent environments across dev/test/prod | Containers via ECS or EKS |
| Short-lived, event-driven functions | AWS Lambda |
| Containers without managing servers | AWS Fargate |
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
- Under the shared responsibility model, what does AWS manage for an Amazon EC2 instance, and what does the customer manage?
- Which EC2 instance family would best fit a machine learning training workload, and why?
- Why might a workload use Spot Instances for part of its capacity and On-Demand or Reserved Instances for the rest?
- What is the difference between stopping and terminating an EC2 instance?
- How do Amazon EC2 Auto Scaling and Elastic Load Balancing work together to support a highly available application?
- What is the relationship between Amazon ECS, Amazon EKS, and AWS Fargate?
- Why is AWS Lambda often described as having "no idle cost," and how does that compare to billing for an EC2 instance?