← Week 3: Container Orchestration

Day 15: ECS Concepts

Phase 5 · Aug 26, 2026

← Week 3: Container Orchestration

Agenda (2–3 hours)

  • Read (45 min): ECS documentation — task definitions, services, clusters, capacity providers; ECS vs EKS decision guide
  • Study (45 min): How does ECS schedule tasks? What is the difference between a task and a service?
  • Practice (45 min): Define a task definition for a Rust HTTP service; deploy it as an ECS service with 2 desired tasks
  • Challenge (30 min): What happens when an ECS task crashes? How does the service scheduler respond? What are the minimum health check settings to avoid a crash loop?
← Week 3: Container Orchestration

ECS Core Concepts

Cluster
└── Service (desired count: 2, task definition: my-app:3)
    ├── Task (running: container my-app + sidecar)
    └── Task (running: container my-app + sidecar)
  • Cluster: logical grouping of compute (EC2 instances or Fargate)
  • Task definition: blueprint — container image, CPU/memory, env vars, ports, IAM role
  • Task: running instance of a task definition (ephemeral)
  • Service: long-running task manager — maintains desired count, handles replacements
← Week 3: Container Orchestration

Task Definition

{
  "family": "my-rust-api",
  "cpu": "256",
  "memory": "512",
  "networkMode": "awsvpc",
  "containerDefinitions": [{
    "name": "api",
    "image": "123456.dkr.ecr.us-east-1.amazonaws.com/my-rust-api:latest",
    "portMappings": [{ "containerPort": 8080 }],
    "environment": [{ "name": "LOG_LEVEL", "value": "info" }],
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-group": "/ecs/my-rust-api",
        "awslogs-region": "us-east-1",
        "awslogs-stream-prefix": "ecs"
      }
    }
  }],
  "taskRoleArn": "arn:aws:iam::123456:role/my-task-role",
  "executionRoleArn": "arn:aws:iam::123456:role/ecsTaskExecutionRole"
}
← Week 3: Container Orchestration

Capacity Providers

Provider When to use
FARGATE Serverless; no EC2 management
FARGATE_SPOT Up to 70% cheaper; interruptible
EC2 Auto Scaling Group Custom instance types; GPU; savings plans

Capacity provider strategy:

"capacityProviderStrategy": [
  { "capacityProvider": "FARGATE",      "weight": 1, "base": 1 },
  { "capacityProvider": "FARGATE_SPOT", "weight": 3, "base": 0 }
]

3:1 ratio: most tasks on Spot, at least 1 task always on standard Fargate.

← Week 3: Container Orchestration

Key Takeaways

  • ECS services maintain desired task count; the scheduler replaces failed tasks automatically
  • Task definitions are immutable and versioned; services pin to a revision
  • awsvpc networking gives each task its own ENI and private IP — no port conflicts
  • Capacity provider strategies blend cost and reliability across Fargate/EC2/Spot

Tomorrow: ECS with Fargate — VPC networking, security groups, and ECR image pull.