ECS and Container Basics
Learn what containers are, what Amazon ECS does, and how clusters, tasks, and services fit together.
Learning outcomes
By the end of this lesson, the learner can:
- Explain what a container is in plain terms.
- Explain what Amazon ECS is.
- Distinguish between an ECS cluster, task, and service.
- Recognize the main ECS infrastructure choices: Fargate, EC2, and ECS Managed Instances.
- Choose when ECS is a better fit than plain EC2 or Lambda. (AWS Documentation)
Key terms
- Container: A packaged application unit that includes the application and its dependencies so it can run consistently across environments. In ECS, containers are the application units you place inside tasks and services. This is reflected throughout the ECS docs, where task definitions describe one or more containers that run together. (AWS Documentation)
- Amazon ECS: Amazon Elastic Container Service, AWS's container orchestration service for running containerized applications. ECS organizes workloads into clusters, tasks, and services. (AWS Documentation)
- Cluster: A logical grouping of tasks or services that provides the infrastructure capacity for containerized applications. (AWS Documentation)
- Task: The running unit of work in ECS, based on a task definition that describes one or more containers that should run together. This is shown in the ECS architecture guidance, where related containers are grouped in one task definition. (AWS Documentation)
- Service: An ECS construct that maintains the desired number of running tasks and can integrate with load balancers and auto scaling. (AWS Documentation)
- Fargate: The serverless compute option for ECS where you pay for the resources your tasks use and do not manage the underlying infrastructure. (AWS Documentation)
- ECS on EC2: The ECS option where your containers run on EC2 instances that you manage. (AWS Documentation)
- ECS Managed Instances: A newer ECS infrastructure type where AWS fully manages the underlying EC2 instances, including provisioning, patching, and scaling. AWS currently recommends this for most new workloads. (AWS Documentation)
What containers are
ECS is AWS's service for running containers in a managed way. Instead of thinking in terms of "one server and the apps on it," ECS helps you think in terms of containerized workloads running as tasks and services inside clusters. AWS says a cluster is the logical grouping, tasks are the work units, and services maintain the desired number of running tasks. (AWS Documentation)
A simple memory rule:
- Container = packaged app
- Task = running unit
- Service = keeps tasks running
- Cluster = where they live (AWS Documentation)
1) What a container is
In plain terms, a container is a packaged application environment. In ECS, you usually define one or more containers that should run together in a task definition, and then ECS runs them as a task. AWS's ECS architecture guidance explicitly discusses grouping related containers in a task definition, such as a frontend container and a log-streaming container that must run together. (AWS Documentation)
Key takeaway:
- a container is not the whole server
- it is the packaged app unit you want AWS to run consistently
2) What Amazon ECS is
AWS says an ECS cluster is a logical grouping of tasks or services that provides infrastructure capacity for your containerized applications. ECS offers multiple infrastructure types so you can run the same container model with different levels of control and operational overhead. (AWS Documentation)
Key takeaway:
- ECS is not just "containers on one machine"
- it is the service that helps schedule, run, maintain, and scale containerized applications
3) The three ECS concepts you must know
A) Cluster
AWS says a cluster is the logical grouping of tasks or services and includes the infrastructure capacity they run on. Clusters are Region-specific. (AWS Documentation)
B) Task
A task is the running unit in ECS, based on a task definition. AWS's ECS guidance shows that task definitions group the containers used for a common purpose together. (AWS Documentation)
C) Service
AWS says an ECS service maintains the desired number of tasks, supports service auto scaling, and can integrate with load balancers. (AWS Documentation)
A simple way to say it:
- cluster = the environment
- task = one running container workload
- service = the thing that keeps the workload running reliably
4) ECS infrastructure choices
AWS currently documents three primary infrastructure types for ECS clusters:
A) ECS Managed Instances
AWS fully manages the underlying EC2 instances, including provisioning, patching, and scaling. AWS says this is the recommended option for most workloads because it balances performance, cost effectiveness, and operational simplicity. (AWS Documentation)
B) Fargate
AWS describes Fargate as the serverless compute option where you pay only for the resources your tasks use and do not manage infrastructure. It is ideal for variable workloads and for getting started quickly. (AWS Documentation)
C) EC2
AWS says ECS on EC2 gives you full control over the underlying EC2 instances, including instance selection, configuration, and maintenance. (AWS Documentation)
5) Fargate vs EC2 vs Managed Instances
A simple comparison:
| Infrastructure choice | Mental model |
|---|---|
| Fargate | Serverless containers |
| ECS Managed Instances | AWS-managed EC2-backed containers |
| ECS on EC2 | Containers on servers you manage |
CSV version:
Infrastructure choice,Mental model
Fargate,Serverless containers
ECS Managed Instances,AWS-managed EC2-backed containers
ECS on EC2,Containers on servers you manage
AWS documents these three infrastructure types and their intended use cases directly in the ECS cluster guidance. (AWS Documentation)
6) Where load balancing and scaling fit
AWS says ECS services can integrate with Elastic Load Balancing and support service auto scaling. That means ECS does not just run containers once. It can keep the desired number of tasks running, attach them to load balancers, and scale them up or down over time. (AWS Documentation)
Key takeaway:
- ECS service = more than "run container now"
- it also means "keep it available and scalable"
7) When ECS is a better fit than EC2
Choose ECS over plain EC2 when:
- you want to deploy apps as containers
- you want orchestration around tasks and services
- you want built-in service scaling and load-balancer integration
- you want to avoid treating each workload like a hand-managed server (AWS Documentation)
A simple example:
- a frontend API and a backend API each run as separate containerized services, and ECS keeps the desired task count running behind a load balancer
8) When ECS is a better fit than Lambda
Choose ECS over Lambda when:
- your app is naturally packaged as a containerized service
- you want long-running services rather than short function executions
- you want more control over runtime packaging than a simple function model provides
This is a practical inference from ECS's service/task model and from Lambda's function model covered earlier. ECS is built for persistent containerized services, while Lambda is built for event-driven function execution. Supported by the ECS service model and capacity model docs. (AWS Documentation)
9) A simple first mental model
A strong mental model for ECS is:
- Build or obtain a container image.
- Describe how it should run in a task definition.
- Put it in a cluster.
- Run it as a task or as a service.
- Optionally attach a load balancer and scaling policy. (AWS Documentation)
That is enough to understand the shape of ECS before going deeper.
Quick comparison table
| Topic | ECS |
|---|---|
| What it manages | Containerized applications |
| Main building blocks | Cluster, task, service |
| Infra options | Fargate, ECS Managed Instances, EC2 |
| Best for | Running and scaling containerized apps |
| Can integrate with | Load balancers and auto scaling |
CSV version:
Topic,ECS
What it manages,Containerized applications
Main building blocks,"Cluster, task, service"
Infra options,"Fargate, ECS Managed Instances, EC2"
Best for,Running and scaling containerized apps
Can integrate with,Load balancers and auto scaling
This summary follows the ECS cluster, service, and launch-type documentation. (AWS Documentation)
Micro-activity 1: Pick the better fit
Micro-activity 2: Explain the hierarchy
Match the ECS term to its meaning
Match each ECS concept to the correct definition.
Examples
Choose one, then match it on the right
Characteristics
Select an example first
0 of 3 matched so far.
Summary
Amazon ECS is AWS's container orchestration service for running containerized applications. AWS describes clusters as the logical grouping, tasks as the units of work, and services as the resources that maintain desired task counts and support scaling and load balancing. (AWS Documentation)
The most important idea is that ECS gives you a structured way to run containers with different infrastructure choices:
- Fargate for serverless containers
- ECS Managed Instances for AWS-managed EC2-backed containers
- EC2 for maximum underlying control (AWS Documentation)
The simplest memory rule is:
- ECS = managed way to run containers
- EC2 = server you manage
- Lambda = function you run on demand (AWS Documentation)
Knowledge Check
Next lesson
Lesson 4.20: Lightsail