AWS Builder Center
EC2, Containers, or Lambda? Choosing AWS Compute with a Kitchen Analogy

EC2, Containers, or Lambda? Choosing AWS Compute with a Kitchen Analogy

A beginner-friendly guide to choosing between EC2, containers with Fargate, and Lambda, explained as four ways of running a kitchen, with three questions to help you decide.

In one line: EC2 is renting a whole kitchen, containers are standardized cooking stations, Fargate is catering, and Lambda is ordering a single dish.
AWS gives you several ways to run code, and beginners often get stuck choosing. Picture a kitchen. The real question is how much of the kitchen you want to manage yourself.

EC2: rent the whole kitchen

You get a virtual server with full control over the operating system, installed software, and networking. You are also responsible for patching, setting up scaling, and keeping it healthy. It suits custom setups and long-running applications that need that level of control.

Containers: standardized cooking stations

A container packages your app with everything it needs, so it runs the same way everywhere. Amazon ECS and Amazon EKS (managed Kubernetes) orchestrate containers. You can run them on EC2 instances that you manage, or on AWS Fargate.

Fargate: catering

With Fargate you provide the recipe, which is your container, and AWS provides the kitchen. There are no servers to manage. You define the CPU and memory your tasks need.

Lambda: order a single dish

Lambda runs your code in response to events such as an HTTP request, a file upload, or a schedule. There are no servers to manage, it scales automatically, and you pay for the time your code runs. A single invocation can run for up to 15 minutes, so it isn't meant for long jobs.

The trade-offs

  • EC2: the most control and the most responsibility
  • Containers: consistent environments, with some orchestration to learn
  • Fargate: less to manage than EC2, but less low-level control
  • Lambda: the least to manage, but with a time limit and possible cold starts, which is extra delay on the first request after a period of inactivity

Three questions to help you choose

  1. Do I need control over the operating system or special software? Consider EC2.
  1. Is my app already in a container, or does it run continuously? Consider ECS with Fargate, or EKS if you use Kubernetes.
  1. Is it short, event-driven work with unpredictable traffic? Consider Lambda.

You can change your mind later

This isn't a permanent choice. Many real systems mix these options, for example a container service for the main app and Lambda functions for small background tasks.

Your turn

Which one did you try first, and what surprised you?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article