Topic lessonTopic: Containers, ECS and Fargate
Amazon ECS basics: task definitions, tasks and services explained
A task definition describes what to run, a task is an execution, and a service maintains a desired number of tasks. Amazon Elastic Container Service (ECS) manages containerized applications. Follow a fictional two-task report API to distinguish registration, execution and updates.
Identify definitions, executions and their service, then explain what registration or a stopped task changes and what remains unproved.
An image packages application files and runtime requirements; a container is a process environment created from it. This is a fixed reading exercise. No AWS account, Docker execution, real logs or credentials are needed.
Separate configuration, execution, maintenance and compute
- Service → Task definition :7References the definition to use
- Service → Tasks A and BSchedules and replaces toward desired count
- Tasks A and B → Compute capacityRun on the selected compute capacity
- Task definition :7
- Image, CPU, memory and other settings
- Service
- References revision :7; desired 2
- Tasks A and B
- Each executes revision :7
- Compute capacity
- Fargate in this example
| Term | Role in this example | Common confusion |
|---|---|---|
| Task definition | report-api:7: a revision of execution settings. | An existing definition need not have a running task. |
| Task | demo-a and demo-b: separate executions. | One task can contain multiple containers. |
| Service | reports-training: maintains desired count 2. | Desired 2 does not establish two healthy HTTP responders. |
| Cluster | A logical grouping of tasks and services. | The cluster is not itself a single server. |
This example uses Fargate for compute. ECS and Fargate are not synonyms: options also include customer-managed EC2 and ECS Managed Instances, where AWS manages the underlying EC2 infrastructure. OS, capacity and maintenance responsibilities depend on that choice.
Registering a revision does not update existing tasks
A family groups related task definitions; a revision identifies a version within it. report-api:7 and report-api:8 are different revisions in one family. Keep configuration and execution separate so you can identify which revision a task used.
Definition report-api:7 image=A
Definition report-api:8 image=B [newly registered]
Service reports-training definition=report-api:7 desired=2
Task demo-a definition=report-api:7 lastStatus=RUNNING
Task demo-b definition=report-api:7 lastStatus=RUNNINGT1 adds only definition :8. The service still references :7, and demo-a and demo-b remain executions of :7. Adopting :8 requires selecting it for an execution or service update. Revision 8 does not mean eight running tasks.
| Object | Before | After |
|---|---|---|
| Registered definitions | :7 | :7 and :8 |
| Service reference | :7 | :7 |
| demo-a / demo-b revisions | :7 / :7 | :7 / :7 |
| Desired count | 2 | 2 |
Who replaces a stopped task?
T2: if demo-a belongs to the service and stops, the service scheduler attempts a replacement toward desired count 2. With T1 unchanged, the service uses :7. The stopped task does not turn into a :8 execution.
Launch depends on capacity, permissions, image retrieval, networking and other conditions. Repeated failures can slow further attempts. Maintenance toward a desired count and two healthy tasks immediately available are different claims.
| Execution type | What to consider after it stops |
|---|---|
| Task owned by this service | The service attempts replacement toward its target; verify the outcome separately. |
| Standalone RunTask with no service | No owning service maintains desired count; examine any separately designed rerun mechanism. |
Separate startup permissions from application permissions
An agent supports execution work such as container startup and log delivery. Distinguish that actor from application code reading business data when assigning permissions.
| Role | Used by | Example purpose |
|---|---|---|
| Task execution role | ECS / Fargate agents | Retrieve a private image and deliver configured logs with the required permissions. |
| Task role | Application code in a container | Read reports through an authorized S3 API. |
An application S3 failure is not a reason to broaden the execution role. Identify the caller, operation and resource, then inspect the appropriate role and minimum permissions. IAM authorization alone does not establish successful DNS, routing or TLS connectivity.
Check lifecycle, health and request success separately
A health check tests a configured condition using a command or endpoint. A load balancer (LB) distributes requests to targets. Keep track of the condition and path each observation actually tests.
| Observation | What it establishes | What still needs checking |
|---|---|---|
| Service desired=2 | A target count of two is configured. | Actual tasks, states and service events. |
| Task lastStatus=RUNNING | Observed task execution state. | Container checks and application responses. |
| Configured health check passes | The condition that check examines passes. | Load-balancer reachability and user operations. |
| A user request succeeds | Success for that request, path and time. | Other requests and continued success need further observations. |
- Identify the cluster, service, referenced revision and desired count.
- Check each running or stopped task’s revision, state and stop reason.
- Use service events and relevant logs to separate placement, image, permission and connectivity issues.
- Check configured health criteria and responses through the user’s path separately.
Practise reading the fixed example
Choose an option to see the result and explanation.
Check, then explain in your own words
- Identify definition, service, tasks and compute in the diagram.
- Explain what changes and stays the same in T1 and T2.
- Distinguish the roles and RUNNING status, then practise with the explanations.
Check your understanding: What should you inspect to verify an ECS execution update?
Inspect the service reference and actual task revisions, states and responses, not just registered definitions.
Configuration registration, count maintenance, launch, health and request success are separate facts. Track the evidence for each when reasoning about changes or failures.
Sources and conditions checked
The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.
- Amazon ECS task definitionsChecked:
Scope and conditionsDefinition revisions versus running tasks; registration is not an update of existing executions. Documentation review, not live AWS verification.
Used in this lessonSeparate configuration, execution, maintenance and compute Registering a revision does not update existing tasks Who replaces a stopped task? Practise reading the fixed example
- Amazon ECS servicesChecked:
Scope and conditionsDesired-count maintenance, replacement and throttled retries; no immediate-success or HTTP-health guarantee. Documentation review, not live AWS verification.
Used in this lessonSeparate configuration, execution, maintenance and compute Who replaces a stopped task? Check lifecycle, health and request success separately Practise reading the fixed example
- Amazon ECS clustersChecked:
Scope and conditionsLogical grouping versus compute; current Fargate, EC2 and Managed Instances options. Documentation review, not live AWS verification.
Used in this lessonSeparate configuration, execution, maintenance and compute
- Amazon ECS rolling deploymentsChecked:
Scope and conditionsService updates versus registration; conditional digest resolution is not automatic adoption of a new tag. Documentation review, not live AWS verification.
Used in this lessonRegistering a revision does not update existing tasks
Scope and conditionsService events as a diagnostic starting point; bounded history and API/console differences. Documentation review, not live AWS verification.
Used in this lessonWho replaces a stopped task? Check lifecycle, health and request success separately
Scope and conditionsAgent permissions for image retrieval and logging versus the application task role. Documentation review, not live AWS verification.
Used in this lessonSeparate startup permissions from application permissions
- Amazon ECS task IAM roleChecked:
Scope and conditionsApplication AWS API permissions; separate reachability and isolation conditions. Documentation review, not live AWS verification.
Used in this lessonSeparate startup permissions from application permissions Practise reading the fixed example
Scope and conditionsTask-definition health checks versus lifecycle, LB and application observations. Documentation review, not live AWS verification.
Used in this lessonCheck lifecycle, health and request success separately
- Amazon ECS task lifecycleChecked:
Scope and conditionsTask lifecycle states are distinct from application health and request success. Documentation review, not live AWS verification.
Used in this lessonCheck lifecycle, health and request success separately Practise reading the fixed example