Clusters, Task Definitions & Services

The four ECS words you need, plus the two IAM roles that trip everyone up.

1 min read
ConceptWhat it isComparison
ClusterA logical group for your containersA project folder
Task definitionA JSON blueprint: image, CPU, memory, ports, env vars, loggingA recipe
TaskOne running copy of a task definitionOne dish made from the recipe
ServiceKeeps N tasks running, replaces failed ones, registers them with a load balancerA 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.

How it flows
  1. 1Image in ECR

    Your packaged app

  2. 2Task definition

    Image + CPU/memory + config

  3. 3Service

    Keeps 2+ tasks running

  4. 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. 1. Your container's code needs to write to S3. Which role gets the permission?