Amazon Elastic Container Service
Container orchestration
AWS's service for running and managing many containers (tasks/services), automatically restarting them on failure and connecting them to load balancers.
- Cost$$ Medium
- Difficulty●●●●●
- Costs money when idle?No
- Managed by AWS
- In examsSAA · DVA · SOA
Think of it asLike a logistics dispatcher loading cargo boxes (containers) onto the right trucks.
Where does ECS fit?
Calls ECS
A real example, step by step
- Your team packages its API as a Docker image and pushes it to ECR.
- You write a task definition: which image, how much CPU and memory, which environment variables, where logs go.
- You create an ECS service that always keeps 3 tasks running behind an Application Load Balancer, using Fargate.
- If a task fails, ECS starts a new one; when you deploy a new version, ECS replaces tasks gradually so the site never goes down.
- When traffic grows, service auto scaling adds tasks based on CPU.
When to use it
✓ Use it when
Running container apps without wanting to learn Kubernetes.
✗ Avoid it when
Your team already knows Kubernetes or needs multi-cloud → EKS.
Common uses
- Containerized microservices behind an ALB
- Background workers reading from SQS
- Batch jobs running as containers
- Bring Docker apps to AWS without learning Kubernetes
ECS, EKS or Fargate?
| What it is | AWS's container orchestrator | Standard Kubernetes managed by AWS | Serverless compute for containers |
|---|---|---|---|
| Learning curve | Low, few concepts | High, you need to know Kubernetes | Low, used with ECS or EKS |
| Separate fee | None | Hourly control plane fee | vCPU and memory per task |
| Best for | AWS-only teams that want simplicity | Teams that know Kubernetes or run in several places | Not managing a cluster of machines |
What does it cost?
- Pricing model: ECS itself is free. You pay for where tasks run: EC2 (per instance-hour) or Fargate (per vCPU and GB of memory).
- Free tier: No ECS charge.
Tasks pulling images through a NAT Gateway (use VPC endpoints for ECR and S3 to avoid this); a separate ALB per service; container logs with no retention period set.
The task role gives permissions to the application in the container (read S3, write DynamoDB); the task execution role lets ECS pull images from ECR and write logs. “No servers to manage” → choose the Fargate launch type.
Try real exam questions
1An ecommerce website is deploying its web application as Amazon Elastic Container Service (Amazon ECS) container instances behind an Application Load Balancer (ALB). During periods of high activity, the website slows down and availability is reduced. A solutions architect uses Amazon CloudWatch alarms to receive notifications whenever there is an availability issue so they can scale out resources. Company management wants a solution that automatically responds to such events. Which solution meets these requirements?
- ASet up AWS Auto Scaling to scale out the ECS service when there are timeouts on the ALB. Set up AWS Auto Scaling to scale out the ECS cluster when the CPU or memory reservation is too high.
- BSet up AWS Auto Scaling to scale out the ECS service when the ALB CPU utilization is too high. Set up AWS Auto Scaling to scale out the ECS cluster when the CPU or memory reservation is too high.
- CSet up AWS Auto Scaling to scale out the ECS service when the service's CPU utilization is too high. Set up AWS Auto Scaling to scale out the ECS cluster when the CPU or memory reservation is too high.
- DSet up AWS Auto Scaling to scale out the ECS service when the ALB target group CPU utilization is too high. Set up AWS Auto Scaling to scale out the ECS cluster when the CPU or memory reservation is too high.
Show answer
Correct answer: C
Scale the number of tasks in the ECS service on the service's own CPU, and scale the cluster's instances on CPU/memory reservation. An ALB has no CPU metric to base scaling on.
2A company is running a multi-tier web application on premises. The web application is containerized and runs on a number of Linux hosts connected to a PostgreSQL database that contains user records. The operational overhead of maintaining the infrastructure and capacity planning is limiting the company's growth. A solutions architect must improve the application's infrastructure. Which combination of actions should the solutions architect take to accomplish this? (Choose two.)
- AMigrate the PostgreSQL database to Amazon Aurora.
- BMigrate the web application to be hosted on Amazon EC2 instances.
- CSet up an Amazon CloudFront distribution for the web application content.
- DSet up Amazon ElastiCache between the web application and the PostgreSQL database.
- EMigrate the web application to be hosted on AWS Fargate with Amazon Elastic Container Service (Amazon ECS).
Show answer
Correct answer: A, E
Move the database to Aurora (a managed service) and run the containers on Fargate with ECS: no servers to operate and no capacity planning. Moving to EC2 still means managing machines yourself.
Frequently asked questions
Is it better to run ECS on Fargate or on EC2?
Fargate removes server management and charges for the CPU and memory of each task. Running on EC2 means managing a cluster of instances yourself, but you choose the instance types (including GPUs) and it is often cheaper for large, steady workloads.
Does ECS cost anything?
ECS has no separate charge. You pay for the resources that run your containers, either Fargate (vCPU and memory per second) or EC2 instances, plus any load balancers, logs and storage you use.
What do AWS exams ask about ECS?
Telling task definitions, tasks and services apart; the task role (permissions for your application) versus the execution role (permissions to pull images and write logs); choosing the Fargate or EC2 launch type; and integration with ALB, ECR and CloudWatch Logs.