AWSDOP-C02
On this page
Beginner-friendly overview

ECS

ECS is AWS's container orchestration service. It runs Docker containers at scale, handling where containers are placed, how they're kept healthy, how they scale up and down, and how they're connected to load balancers and other services.

Why Containers, and Why a Scheduler?

Containers package your application with everything it needs to run โ€” code, runtime, libraries, configuration โ€” into a portable image. You build the image once and it runs the same way everywhere: on a laptop, in CI, in production.

The challenge with containers at scale is orchestration: if you have 50 containers to run across 20 servers, which container goes on which server? What happens when a container crashes? How do you update them without downtime? ECS handles all of this automatically.

Two Launch Modes

Fargate โ€” you define the CPU and memory your container needs, and AWS handles the underlying servers entirely. There's no fleet of EC2 instances to manage, patch, or scale. This is the default choice for most teams.

EC2 launch type โ€” ECS places containers on EC2 instances that you manage. You control the instance types, can use spot instances for cost savings, and have access to instance-level features (GPU, specific networking, local storage). Use this when you need more control than Fargate offers.

Key Concepts

Task Definition โ€” a blueprint for your container: which Docker image to use, how much CPU and memory to allocate, which ports to expose, which environment variables to set, and which IAM role the container should run as.

Task โ€” a running instance of a task definition. A task can contain one or more tightly-coupled containers (think an application container plus a log sidecar).

Service โ€” ECS's way of keeping N copies of a task running at all times. If a container crashes, the service starts a replacement. Services integrate with Application Load Balancers to distribute traffic across running tasks.

Cluster โ€” a logical grouping of tasks and services. In Fargate mode, the cluster is mostly just a namespace; in EC2 mode, it includes the underlying instances.

How Deployment Works

When you update a service with a new task definition (say, a new container image), ECS performs a rolling update by default: it starts new tasks with the new version, waits for them to pass health checks, then stops old tasks. No downtime, and you can roll back by pointing the service back to the previous task definition.