Clusters, Task Definitions & Services
The four ECS words you need, plus the two IAM roles that trip everyone up.
1 min read
| Concept | What it is | Comparison |
|---|---|---|
| Cluster | A logical group for your containers | A project folder |
| Task definition | A JSON blueprint: image, CPU, memory, ports, env vars, logging | A recipe |
| Task | One running copy of a task definition | One dish made from the recipe |
| Service | Keeps N tasks running, replaces failed ones, registers them with a load balancer | A head chef keeping enough dishes on the counter |
Use a service for things that should always run, like web apps and APIs. Use a standalone task for one-off jobs, like a nightly report or a database migration.
The two roles (common confusion!)
- Task execution role: used by ECS itself to pull your image from ECR and send logs to CloudWatch.
- Task role: used by your app code inside the container to call AWS services, such as reading from S3.
Watch out
If your app gets AccessDenied calling DynamoDB, add the permission to the task role, not the execution role.
- 1Image in ECR
Your packaged app
- 2Task definition
Image + CPU/memory + config
- 3Service
Keeps 2+ tasks running
- 4Load balancer
Routes users to healthy tasks
Key takeaways
- Task definition = blueprint, task = running copy, service = keeps tasks running.
- The execution role is for ECS (pull images, write logs), the task role is for your code.
- Use services for always-on apps and standalone tasks for one-off jobs.
Check your understanding
Pick an answer to see the explanation.
1. Your container's code needs to write to S3. Which role gets the permission?