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.
| Service | Best for | Trade-off |
|---|---|---|
| ECS | Long-running containers, simple ops | AWS-specific APIs |
| EKS | Teams that want managed Kubernetes | More moving parts to learn |
| Lambda | Short, event-driven functions | 15-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
# ECS runs containers; Lambda runs functions.
# This tutorial focuses on ECS:
aws ecs list-services --cluster my-clusterWhen 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.
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.
aws lambda invoke \
--function-name process-s3-event \
--payload '{"bucket":"my-bucket","key":"report.csv"}' \
--cli-binary-format raw-in-base64-out \
response.jsonList EKS Node Groups vs ECS Services
Contrasts the EKS node-group model with the ECS service model for running containerized workloads.
# 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