ECS vs EKS vs Lambda

Choosing between ECS, EKS, and Lambda for running your workloads.

AWS gives you several ways to run code. Picking the right one saves a lot of effort.

ServiceBest forTrade-off
ECSLong-running containers, simple opsAWS-specific APIs
EKSTeams that want managed KubernetesMore moving parts to learn
LambdaShort, event-driven functions15-min limit, cold starts

Rule of thumb

Choose ECS when you have containers and want the least operational overhead. Choose EKS when you need portable Kubernetes. Choose Lambda for tiny, spiky, event-driven work.

Example

Example · bash
# ECS runs containers; Lambda runs functions.
# This tutorial focuses on ECS:
aws ecs list-services --cluster my-cluster

When to use it

  • A startup chooses ECS over EKS to avoid Kubernetes learning-curve overhead while still running long-lived containerized services.
  • A data-engineering team uses Lambda for event-driven ETL transforms but ECS for their multi-hour Spark batch jobs that exceed Lambda's 15-minute limit.
  • A platform team picks EKS when they need custom Kubernetes operators, service meshes, and multi-cluster federation that ECS does not support.

More examples

Run a Long Batch Job on ECS

Launches a one-off ECS Fargate task suitable for batch jobs that run longer than Lambda's 15-minute limit.

Example · bash
aws ecs run-task \
  --cluster demo-cluster \
  --launch-type FARGATE \
  --task-definition my-job:3 \
  --network-configuration \
    'awsvpcConfiguration={subnets=[subnet-abc],securityGroups=[sg-xyz],assignPublicIp=ENABLED}'

Invoke Lambda for Event-Driven Work

Calls a Lambda function directly, illustrating the event-driven pattern preferable over ECS for sub-15-minute stateless tasks.

Example · bash
aws lambda invoke \
  --function-name process-s3-event \
  --payload '{"bucket":"my-bucket","key":"report.csv"}' \
  --cli-binary-format raw-in-base64-out \
  response.json

List EKS Node Groups vs ECS Services

Contrasts the EKS node-group model with the ECS service model for running containerized workloads.

Example · bash
# EKS: check managed node groups
aws eks list-nodegroups --cluster-name my-eks-cluster

# ECS: check services in a cluster
aws ecs list-services --cluster my-ecs-cluster

Discussion

  • Be the first to comment on this lesson.