Chapter 11 of 20
Compute on AWS: Amazon EC2 and Core Compute Options
Explore how AWS provides raw compute capacity and managed compute services, and see how different options map to real-world application needs.
Big Picture: Compute on AWS and Where EC2 Fits
Where Compute Fits
You will connect three ideas: Amazon EC2 as raw compute, managed compute services that hide infrastructure details, and how to choose between them for cost, control, and flexibility.
Global Infrastructure Context
Recall: AWS Region is a physical location where AWS clusters data centers. An Availability Zone is one or more discrete data centers with redundant power, networking, and connectivity in an AWS Region.
What EC2 Provides
Amazon EC2 gives you virtual machines called instances. You pick CPU, memory, storage type, and networking, then install and manage the operating system and applications yourself.
Managed Compute Around EC2
Services such as AWS Lambda, AWS Fargate, Amazon ECS, Amazon EKS, and Elastic Beanstalk sit on top of EC2 and abstract away more infrastructure in exchange for less low-level control.
Shared Responsibility Reminder
Under the AWS shared responsibility model, AWS secures the infrastructure that runs EC2, while you are responsible for securing the OS, applications, and data on your instances.
Amazon EC2 Basics: Instances, AMIs, and Sizing
Elastic Compute Cloud
Amazon EC2 is the Elastic Compute Cloud: virtual servers you can start, stop, and resize on demand, scaling capacity up or down as your workload changes.
Instances and Types
An EC2 instance is a virtual server. The instance type (for example, t3.micro, m7g.large) defines CPU, memory, and network performance, and each family has multiple sizes.
Amazon Machine Images
An AMI is a template for launching instances. It includes an operating system and optionally preinstalled software. You can use AWS, marketplace, or custom AMIs.
Storage and Networking
EC2 instances usually boot from EBS volumes and run inside your VPC. Security groups act as virtual firewalls controlling inbound and outbound traffic.
Instance Lifecycle and Billing
Instances move through states like pending, running, stopped, terminated. You pay while instances run, and you keep paying for EBS volumes until you delete them.
EC2 Instance Families and Common Use Cases
Choosing Instance Families
Instance families bundle CPU, memory, storage, and networking characteristics. Your goal is to match these characteristics to the needs of your workload.
General Purpose
General purpose (A, T, M) instances balance CPU, memory, and network. They are good defaults for web apps, small databases, and dev/test environments.
Compute and Memory Optimized
Compute optimized (C) are for CPU-intensive tasks like media transcoding. Memory optimized (R, X) are for RAM-heavy tasks like in-memory databases and caching.
Storage and Accelerated
Storage optimized (I, D) provide fast, large local storage for low-latency data access. Accelerated computing (P, G, Inf) add GPUs or custom chips for ML and graphics.
Exam Focus
For Cloud Practitioner, you do not need model numbers. Focus on recognizing which family is appropriate for CPU-heavy, memory-heavy, storage-heavy, or GPU workloads.
EC2 Pricing Models Overview: On-Demand, Reserved, Spot
Why Multiple Pricing Models?
EC2 pricing models let you trade off flexibility, commitment, and cost. You decide whether you prefer pay-as-you-go, commit-and-save, or use spare capacity cheaply.
On-Demand Instances
On-Demand means pay per second or hour with no commitment. It offers maximum flexibility but the highest price per unit. Ideal for new or unpredictable workloads.
Reserved Instances and Savings Plans
Reserved Instances and Savings Plans give discounts when you commit to 1 or 3 years of consistent usage. RIs are less flexible; Savings Plans are more flexible but conceptually similar.
Spot Instances
Spot Instances use spare AWS capacity at deep discounts, but AWS can interrupt them when capacity is needed elsewhere. They suit fault-tolerant, flexible jobs.
Combining Models
A common strategy: baseline capacity on Reserved/Savings Plans, unpredictable spikes on On-Demand, and extra flexible work on Spot for maximum savings.
Mapping EC2 Pricing to Workload Patterns (Scenarios)
Scenario 1: New Startup App
Unpredictable traffic and fast-changing features need flexibility. Start on On-Demand, then move the stable baseline to Reserved Instances or Savings Plans once usage is known.
Scenario 2: Steady HR System
A business-critical HR app used daily for years has predictable usage. Run core capacity on Reserved Instances or Savings Plans, with On-Demand only for occasional spikes.
Scenario 3: Batch Transcoding
Video transcoding jobs are independent and retryable. Use Spot Instances in an Auto Scaling group to process them cheaply, tolerating interruptions.
Exam Thinking Pattern
Ask: Is usage predictable or spiky? Can the workload be interrupted? How long will it run? Use those answers to choose On-Demand, Reserved/Savings, or Spot.
Quick Check: EC2 Pricing Models
Test your understanding of EC2 pricing options.
Your team runs a data analytics job that can be stopped and restarted without issues. It needs to process a large backlog as cheaply as possible, and completion time is flexible. Which EC2 pricing model is the BEST fit?
- On-Demand Instances
- Reserved Instances or Savings Plans
- Spot Instances
- Dedicated Hosts
Show Answer
Answer: C) Spot Instances
Spot Instances are ideal for fault-tolerant, flexible workloads like batch analytics. They use spare capacity at deep discounts but can be interrupted. On-Demand is more expensive; Reserved/Savings target predictable long-term usage; Dedicated Hosts are for licensing and compliance needs, not cost-only optimization.
Other Core Compute Services: Lambda, Fargate, ECS, EKS, Beanstalk
Why Managed Compute?
Managed compute services reduce how much infrastructure you manage. You trade some low-level control for faster deployment and less operational work.
AWS Lambda
AWS Lambda runs your code without servers. You upload functions that run on events and pay per request and compute time. Ideal for event-driven, spiky workloads.
AWS Fargate and ECS
ECS orchestrates containers. With Fargate, you run ECS tasks without managing EC2 instances; you specify CPU and memory and AWS handles provisioning.
Amazon EKS and Beanstalk
EKS is managed Kubernetes, running on EC2 or Fargate. Elastic Beanstalk lets you deploy code while it sets up EC2, load balancing, and scaling for you.
Exam-Level Decision Rule
Need full server control? Use EC2. Want to focus more on code and less on infrastructure? Choose Lambda, Fargate, ECS/EKS, or Elastic Beanstalk.
Thought Exercise: Choosing Between EC2 and Managed Compute
Apply what you have learned by reasoning through three short scenarios. There are no single "right" answers, but some choices align better with exam expectations.
- IoT data ingestion with unpredictable spikes
- Devices send small messages that need light processing and storage.
- Spikes during firmware updates; quiet at night.
- Options to consider:
- EC2 Auto Scaling group of small instances.
- AWS Lambda functions triggered by an API Gateway endpoint.
- Prompt: Which would you choose and why? Think about cost during idle time, scaling speed, and operational effort.
- Legacy application requiring OS-level access
- Old app needs custom kernel modules and specific OS tuning.
- Vendor only supports certain Linux distributions with root access.
- Options:
- Re-platform onto containers with Fargate.
- Run on EC2 instances you fully control.
- Prompt: Which is safer in the short term? How does the shared responsibility model influence your choice?
- Internal microservice platform for many small teams
- Dozens of microservices, each in its own container.
- Teams want consistent deployment pipelines and autoscaling.
- Options:
- Amazon ECS on EC2.
- Amazon ECS on Fargate.
- AWS Lambda for each microservice.
- Prompt: Which would you propose as a default and why? Consider team skills, operational overhead, and cost.
Pause and write down your choices and reasoning. Then compare to the summary in the next step.
Walkthrough: Reasoning About Compute Selection
IoT Spikes: Why Lambda?
IoT traffic is spiky and event-driven. Lambda scales automatically and charges only when requests arrive, avoiding idle EC2 costs and reducing operational work.
Legacy App: Why EC2?
Legacy apps needing custom kernels or OS tuning require full server control. EC2 lets you manage the OS, which managed services like Fargate intentionally hide.
Microservices: ECS on Fargate
ECS on Fargate is a strong default: ECS orchestrates containers, Fargate removes EC2 management. Teams get consistent deployments with less infrastructure overhead.
Exam Decision Heuristic
If the scenario stresses control and custom OS, choose EC2. If it stresses less operations and event or container focus, choose Lambda, Fargate, or similar managed options.
Quiz: EC2 vs Managed Compute
Check you can distinguish EC2 from higher-level compute services.
A startup wants to run a simple web application quickly without learning server administration. They are fine with AWS creating and managing the underlying EC2 instances, but they still want full control over their application code and configuration. Which service is the BEST fit?
- Amazon EC2 directly
- AWS Lambda functions only
- AWS Elastic Beanstalk
- Amazon EKS with self-managed worker nodes
Show Answer
Answer: C) AWS Elastic Beanstalk
AWS Elastic Beanstalk lets you deploy application code while it provisions and manages EC2, load balancing, and scaling. EC2 directly and EKS require more infrastructure knowledge. Lambda is great for event-driven functions, not full web apps that need a long-running environment by default.
Key Term Review: EC2 and Compute Options
Flip these cards to reinforce core concepts.
- Amazon EC2
- A web service that provides resizable compute capacity in the cloud in the form of virtual servers called instances, giving you control over the operating system and software.
- EC2 Instance
- A virtual server in the cloud. You choose its instance type, operating system, storage, and networking configuration.
- Amazon Machine Image (AMI)
- A template that contains a software configuration, including an operating system and optional additional software, used to launch EC2 instances.
- On-Demand Instances
- EC2 pricing model where you pay for compute capacity by the second or hour with no long-term commitment, offering maximum flexibility at the highest per-unit cost.
- Reserved Instances / Savings Plans
- Pricing options where you commit to a consistent amount of usage (typically 1 or 3 years) in exchange for significant discounts compared to On-Demand prices.
- Spot Instances
- EC2 instances that use unused AWS capacity at steep discounts, but can be interrupted by AWS when capacity is needed elsewhere; best for fault-tolerant, flexible workloads.
- General Purpose Instances
- EC2 instance family type that balances compute, memory, and networking resources, suitable for many common applications like web servers and small databases.
- Compute Optimized Instances
- EC2 instances designed for compute-bound applications that benefit from high-performance processors, such as high-performance web servers or scientific modeling.
- AWS Lambda
- A serverless compute service that lets you run code without provisioning or managing servers, charging you per request and execution time.
- AWS Fargate
- A serverless compute engine for containers that works with ECS and EKS, allowing you to run containers without managing EC2 instances.
- AWS Elastic Beanstalk
- A service for deploying and scaling web applications that automatically handles provisioning of EC2, load balancing, scaling, and monitoring while you focus on code.
Pulling It Together: Cost, Performance, and Next Steps
Well-Architected and Compute
Compute choices affect cost, performance, operations, and reliability. The AWS Well-Architected Framework highlights aligning instance types and services with these pillars.
Five-Step Selection Flow
1) Define workload type. 2) Judge predictability. 3) Decide control needs. 4) Pick EC2 or managed compute. 5) Choose a pricing model that fits usage and risk.
Exam Patterns to Expect
Questions often describe a scenario and expect you to pick both a compute option (EC2 vs Lambda/Fargate/Beanstalk) and a pricing model (On-Demand, Reserved/Savings, Spot).
Your Skarp Next Steps
Use the upcoming mock exam to pressure-test these ideas. Weak topics will show up in your spaced review queue, and the gap guide will deepen whichever domains need work.
Key Terms
- AWS Lambda
- A serverless compute service that lets you run code without provisioning or managing servers, charging you per request and execution time.
- AWS Region
- An AWS Region is a physical location in the world where we cluster data centers.
- Amazon EC2
- A web service that provides resizable compute capacity in the cloud in the form of virtual servers called instances, giving you control over the operating system and software.
- Amazon ECS
- A fully managed container orchestration service that makes it easy to run, stop, and manage Docker containers on a cluster of EC2 instances or with AWS Fargate.
- Amazon EKS
- A managed Kubernetes service that makes it easy to run Kubernetes on AWS without having to install and operate your own Kubernetes control plane.
- AWS Fargate
- A serverless compute engine for containers that works with ECS and EKS, allowing you to run containers without managing EC2 instances.
- EC2 Instance
- A virtual server in the cloud. You choose its instance type, operating system, storage, and networking configuration.
- Savings Plans
- A flexible pricing model where you commit to a consistent amount of compute spend per hour for 1 or 3 years, in exchange for lower prices on EC2 and some other compute services.
- Spot Instances
- EC2 instances that use unused AWS capacity at steep discounts, but can be interrupted by AWS when capacity is needed elsewhere; best for fault-tolerant, flexible workloads.
- Availability Zone
- An Availability Zone is one or more discrete data centers with redundant power, networking, and connectivity in an AWS Region.
- Reserved Instances
- A pricing option where you commit to using specific EC2 instance attributes for a 1-year or 3-year term in exchange for a significant discount compared to On-Demand prices.
- On-Demand Instances
- EC2 pricing model where you pay for compute capacity by the second or hour with no long-term commitment, offering maximum flexibility at the highest per-unit cost.
- AWS Elastic Beanstalk
- A service for deploying and scaling web applications that automatically handles provisioning of EC2, load balancing, scaling, and monitoring while you focus on code.
- General Purpose Instances
- EC2 instance family type that balances compute, memory, and networking resources, suitable for many common applications like web servers and small databases.
- Amazon Machine Image (AMI)
- A template that contains a software configuration, including an operating system and optional additional software, used to launch EC2 instances.
- Memory Optimized Instances
- EC2 instances designed to deliver fast performance for workloads that process large data sets in memory, such as in-memory databases and real-time big data analytics.
- Compute Optimized Instances
- EC2 instances designed for compute-bound applications that benefit from high-performance processors, such as high-performance web servers or scientific modeling.
- AWS Well-Architected Framework
- The AWS Well-Architected Framework describes the key concepts, design principles, and architectural best practices for designing and running workloads in the cloud.
- AWS shared responsibility model
- Security and compliance are shared responsibilities between AWS and the customer.