Skip to main content

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

CriterionECSEKSFargate
TypeNative AWS orchestratorManaged KubernetesServerless compute
ComplexityLowHighVery low
PortabilityAWS onlyMulti-cloudAWS only
Infra managementEC2 or FargateEC2 or FargateNone
Learning curveGentleSteepVery 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

ConceptDescription
ClusterLogical grouping of resources
Task DefinitionBlueprint for the containers (like a Dockerfile)
TaskA running instance of a Task Definition
ServiceMaintains N tasks running
Container InstanceEC2 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

ComponentCost
ECSFree
EC2 InstancesStandard EC2 price
Data TransferStandard price

6.2 Fargate

ResourcePrice (eu-west-1)
vCPU~$0.04048/hour
Memory~$0.004445/GB/hour

Example: 1 vCPU, 2GB RAM, 24h

  • vCPU: 0.04048×24=0.04048 × 24 = 0.97
  • Memory: 0.004445×2×24=0.004445 × 2 × 24 = 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

  1. Open the ECS console
  2. "Create Cluster"
  3. Choose the template (Networking only for Fargate)
  4. Name the cluster
  5. 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


← Back to the table of contents