AWSCloud Visual Academy

Comparison lab

Amazon EC2 vs AWS Lambda vs AWS Fargate

EC2 runs a machine. Lambda runs a function. Fargate runs a container.

All comparisons

Picture the difference

Workload → virtual machine (EC2) / short function invocation (Lambda) / managed container compute (Fargate)

OptionWhat it doesExam clueWhen not to use it
Amazon EC2On-demand virtual machines with control over the operating system, instance type, and network placement.virtual machine, instance types, AMI, guest OS, root accessDo not assume AWS patches the guest OS, or choose a VM when an event handler needs no host control.
AWS LambdaServerless function compute that runs code in response to events or direct invocation.functions, event-driven, invocation, concurrency, 15-minute timeoutDo not choose it for jobs that cannot finish within the invocation limit or for software that must control the OS.
AWS FargateServerless compute capacity for running Amazon ECS tasks and supported Amazon EKS pods without managing worker instances.serverless containers, ECS tasks, EKS pods, no host management, CPU and memoryDo not choose it for host-level control, or confuse container compute with a function that runs only for an invocation.

Decision tree

  1. Need control of the guest OS, including custom kernel modules Amazon EC2
  2. Run short-lived code in response to events without managing servers AWS Lambda
  3. Run ECS tasks or EKS pods without managing worker instances AWS Fargate

If none of these clues fit, check the exact requirement before choosing.