On this page
On this page
- What Is ECS
- Core Concepts
- Launch Types
- EC2 Launch Type
- Fargate Launch Type
- Task Definition Deep Dive
- The Two IAM Roles โ This Is a Common Exam Trap
- Secrets Injection
- Networking Modes
- Service Auto Scaling
- Deployment Strategies
- Rolling Update (Default)
- Blue/Green with CodeDeploy
- External Deployments
- Logging
- ECS Anywhere
- ECS vs EKS
- Key Exam Scenarios
- CloudWatch Integration
- Automatically Published (AWS/ECS namespace)
- Requires Setup
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.