Introduction to ECS and Fargate
1 - What is Amazon ECS?
Amazon ECS (Elastic Container Service) is a fully managed container orchestration service that lets you run, stop, and manage Docker containers on a cluster.
2 - ECS vs EKS vs Fargate
2.1 Comparison
| Criterion | ECS | EKS | Fargate |
|---|---|---|---|
| Type | Native AWS orchestrator | Managed Kubernetes | Serverless compute |
| Complexity | Low | High | Very low |
| Portability | AWS only | Multi-cloud | AWS only |
| Infra management | EC2 or Fargate | EC2 or Fargate | None |
| Learning curve | Gentle | Steep | Very gentle |
| Cost | $ | $$ | $$ |
2.2 When to choose what?
Choose ECS if:
- You are 100% on AWS
- You do not need Kubernetes
- You want a simple solution
Choose EKS if:
- You need Kubernetes
- Multi-cloud portability is required
- You have a team with K8s expertise
Choose Fargate if:
- You do not want to manage infrastructure
- Workloads with variable scaling
- Maximum simplicity
3 - ECS architecture
3.1 Main components
3.2 Hierarchy of concepts
| Concept | Description |
|---|---|
| Cluster | Logical grouping of resources |
| Task Definition | Blueprint for the containers (like a Dockerfile) |
| Task | A running instance of a Task Definition |
| Service | Maintains N tasks running |
| Container Instance | EC2 with the ECS agent (EC2 launch type) |
4 - Launch Types
4.1 EC2 Launch Type
Advantages:
- Full control over the infrastructure
- GPU and specialized instances
- Reserved pricing possible
- Access to the instances
Disadvantages:
- Instance management
- Capacity planning
- OS patching
4.2 Fargate Launch Type
Advantages:
- Serverless - no infrastructure to manage
- Pay-per-use
- Instant scaling
- Enhanced security (isolation)
Disadvantages:
- Higher cost per task
- No access to the instances
- Resource limits
5 - Use cases
5.1 Microservices
5.2 Batch Processing
# Task Definition pour batch
{
"family": "batch-processor",
"containerDefinitions": [
{
"name": "processor",
"image": "batch-app:latest",
"command": ["python", "process.py"]
}
]
}
5.3 CI/CD Runners
- Jenkins/GitLab runners on ECS
- Queue-based scaling
- Isolation per container
6 - Pricing
6.1 EC2 Launch Type
| Component | Cost |
|---|---|
| ECS | Free |
| EC2 Instances | Standard EC2 price |
| Data Transfer | Standard price |
6.2 Fargate
| Resource | Price (eu-west-1) |
|---|---|
| vCPU | ~$0.04048/hour |
| Memory | ~$0.004445/GB/hour |
Example: 1 vCPU, 2GB RAM, 24h
- vCPU: 0.97
- Memory: 0.21
- Total: ~$1.18/day
6.3 Fargate Spot
Up to 70% discount for workloads that tolerate interruptions.
7 - First ECS cluster
7.1 Via the Console
- Open the ECS console
- "Create Cluster"
- Choose the template (Networking only for Fargate)
- Name the cluster
- Configure VPC/Subnets
7.2 Via the CLI
# Créer un cluster
aws ecs create-cluster \
--cluster-name mon-cluster \
--capacity-providers FARGATE FARGATE_SPOT \
--default-capacity-provider-strategy \
capacityProvider=FARGATE,weight=1 \
capacityProvider=FARGATE_SPOT,weight=1
# Vérifier
aws ecs describe-clusters --clusters mon-cluster
7.3 Via CloudFormation
AWSTemplateFormatVersion: '2010-09-09'
Resources:
ECSCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: mon-cluster
CapacityProviders:
- FARGATE
- FARGATE_SPOT
DefaultCapacityProviderStrategy:
- CapacityProvider: FARGATE
Weight: 1
- CapacityProvider: FARGATE_SPOT
Weight: 1
ClusterSettings:
- Name: containerInsights
Value: enabled
Tags:
- Key: Environment
Value: Production
Summary
In this chapter, we discovered:
- ECS as AWS's container orchestrator
- The differences between ECS, EKS and Fargate
- The architecture and components of ECS
- The launch types (EC2 vs Fargate)
- Typical use cases
- Pricing
Next step
In the next chapter, we will dive deeper into the Fundamental concepts of ECS.
→ Next chapter: Fundamental concepts