INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

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.

What you will learn

Identify definitions, executions and their service, then explain what registration or a stopped task changes and what remains unproved.

Prerequisite

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

ECS relationships: references, scheduling and placement, not an HTTP request path
ECS relationships: references, scheduling and placement, not an HTTP request path1: Service — References the definition to use — Task definition :7. 2: Service — Schedules and replaces toward desired count — Tasks A and B. 3: Tasks A and B — Run on the selected compute capacity — Compute capacity123Task definition :7ServiceTasks A and BCompute capacityECS relationships: references, scheduling and placement, not an HTTP request path1: Service — References the definition to use — Task definition :7. 2: Service — Schedules and replaces toward desired count — Tasks A and B. 3: Tasks A and B — Run on the selected compute capacity — Compute capacity123Task definition:7ServiceTasks A and BComputecapacity
  1. Service → Task definition :7References the definition to use
  2. Service → Tasks A and BSchedules and replaces toward desired count
  3. 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
Identify each object by its role
TermRole in this exampleCommon confusion
Task definitionreport-api:7: a revision of execution settings.An existing definition need not have a running task.
Taskdemo-a and demo-b: separate executions.One task can contain multiple containers.
Servicereports-training: maintains desired count 2.Desired 2 does not establish two healthy HTTP responders.
ClusterA 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.

T1: read the service reference and each task revision separately
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=RUNNING

T1 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.

Before and after registration alone
ObjectBeforeAfter
Registered definitions:7:7 and :8
Service reference:7:7
demo-a / demo-b revisions:7 / :7:7 / :7
Desired count22

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.

Do not invent service ownership for a standalone task
Execution typeWhat to consider after it stops
Task owned by this serviceThe service attempts replacement toward its target; verify the outcome separately.
Standalone RunTask with no serviceNo 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.

Distinguish the two roles by who uses them
RoleUsed byExample purpose
Task execution roleECS / Fargate agentsRetrieve a private image and deliver configured logs with the required permissions.
Task roleApplication code in a containerRead 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.

Do not turn one status into an end-to-end guarantee
ObservationWhat it establishesWhat still needs checking
Service desired=2A target count of two is configured.Actual tasks, states and service events.
Task lastStatus=RUNNINGObserved task execution state.Container checks and application responses.
Configured health check passesThe condition that check examines passes.Load-balancer reachability and user operations.
A user request succeedsSuccess for that request, path and time.Other requests and continued success need further observations.
  1. Identify the cluster, service, referenced revision and desired count.
  2. Check each running or stopped task’s revision, state and stop reason.
  3. Use service events and relevant logs to separate placement, image, permission and connectivity issues.
  4. 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.

In T1, only :8 is registered. What happens to demo-a?
Read the answer and reason

Answer: It remains an execution of :7; the service still references :7 · T1 is registration alone. No execution or service update selecting :8 is given.

In T2 demo-a stops, with T1 service settings unchanged. Which conclusion is justified?
Read the answer and reason

Answer: The service attempts a :7 replacement; verify launch and health separately · The reference remains :7. Attempted maintenance is not a guarantee of immediate success.

A standalone RunTask execution with no owning service stops. What follows?
Read the answer and reason

Answer: Service desired-count maintenance cannot be assumed · Separate standalone execution from service management; examine any rerun design separately.

Which role should you inspect for the application’s S3 read permission?
Read the answer and reason

Answer: The task role; verify caller, operation and resource · The application uses its task role for AWS APIs; authorization does not prove network success.

demo-b is RUNNING; HTTP responses and health checks are uncollected. What is established?
Read the answer and reason

Answer: The task lifecycle state; health and request success remain unverified · Separate observed state from health and request evidence still needed.

Check, then explain in your own words

  1. Identify definition, service, tasks and compute in the diagram.
  2. Explain what changes and stays the same in T1 and T2.
  3. 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.