AWS ECS & Fargate — Container Services
AWS ECS & Fargate — Container Services
Section titled “AWS ECS & Fargate — Container Services”Amazon Elastic Container Service (ECS) is a fully managed container orchestration service. Fargate is a serverless compute engine for containers that removes the need to manage EC2 servers.
In Azure terms: ECS ≈ Azure Container Apps (Fargate) / Azure Container Instances (ACI) / VMSS-backed container hosting
ECS Core Concepts
Section titled “ECS Core Concepts”| Concept | Description |
|---|---|
| Cluster | Logical grouping of compute resources for running tasks and services |
| Task Definition | Blueprint for your container(s) — image, CPU, memory, ports, env vars, IAM role |
| Task | A running instance of a Task Definition (one-off execution) |
| Service | Maintains a desired count of running tasks, integrates with load balancers |
| Container | The individual Docker container within a task |
| ECR | Elastic Container Registry — private Docker image registry |
ECS Launch Types
Section titled “ECS Launch Types”| Launch Type | Description | Azure Equivalent |
|---|---|---|
| Fargate | Serverless — AWS manages the underlying EC2 servers | Azure Container Apps / ACI |
| EC2 | You manage a fleet of EC2 instances for ECS to place containers on | Azure Container Instances on VMSS |
| External (ECS Anywhere) | Run ECS on your own on-prem or edge servers | Azure Arc |
Fargate — Serverless Containers
Section titled “Fargate — Serverless Containers”With Fargate you only specify CPU and memory — no server management:
You define: AWS manages:- Task Definition - EC2 hosts- CPU/Memory - Patching- Container image - Scaling compute- VPC/Security GroupSupported CPU/Memory combinations:
| vCPU | Memory Options |
|---|---|
| 0.25 vCPU | 0.5, 1, 2 GB |
| 0.5 vCPU | 1, 2, 3, 4 GB |
| 1 vCPU | 2–8 GB |
| 2 vCPU | 4–16 GB |
| 4 vCPU | 8–30 GB |
| 8 vCPU | 16–60 GB |
| 16 vCPU | 32–120 GB |
Sample Task Definition (JSON)
Section titled “Sample Task Definition (JSON)”{ "family": "my-web-app", "networkMode": "awsvpc", "requiresCompatibilities": ["FARGATE"], "cpu": "512", "memory": "1024", "executionRoleArn": "arn:aws:iam::123456789:role/ecsTaskExecutionRole", "containerDefinitions": [ { "name": "web", "image": "123456789.dkr.ecr.us-east-1.amazonaws.com/my-app:latest", "portMappings": [{ "containerPort": 8080, "protocol": "tcp" }], "environment": [ { "name": "ENV", "value": "production" } ], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/ecs/my-web-app", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } } } ]}ECR — Elastic Container Registry
Section titled “ECR — Elastic Container Registry”ECR is AWS’s private Docker container registry — equivalent to Azure Container Registry (ACR):
# Authenticate Docker to ECRaws ecr get-login-password --region us-east-1 | \ docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com
# Create a repositoryaws ecr create-repository --repository-name my-app
# Build and pushdocker build -t my-app .docker tag my-app:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/my-app:latestdocker push 123456789.dkr.ecr.us-east-1.amazonaws.com/my-app:latestECS Service + ALB Pattern
Section titled “ECS Service + ALB Pattern”A standard production deployment:
Internet → ALB (Application Load Balancer) ↓ Target Group ↓ ECS Fargate Service (desired count: 3) ├── Task 1 (container: my-app) ├── Task 2 (container: my-app) └── Task 3 (container: my-app)ECS handles:
- Health checks and task replacement
- Rolling deployments (or blue/green via CodeDeploy)
- Auto-scaling based on CPU/memory/custom metrics
ECS vs EKS — When to Choose
Section titled “ECS vs EKS — When to Choose”| Factor | ECS | EKS (Kubernetes) |
|---|---|---|
| Simplicity | Simpler AWS-native API | More complex but industry-standard |
| AWS integration | Deep (IAM, ALB, CloudWatch) | Good (but requires more config) |
| Portability | AWS-only | Kubernetes — portable across clouds |
| Learning curve | Lower | Higher |
| Community ecosystem | AWS-specific | Massive Kubernetes ecosystem |
Rule of thumb: Use ECS (Fargate) if you want simplicity and stay AWS-native. Use EKS if you need Kubernetes compatibility, advanced scheduling, or portability.
CLI Examples
Section titled “CLI Examples”# Register a task definitionaws ecs register-task-definition --cli-input-json file://task-def.json
# Create a clusteraws ecs create-cluster --cluster-name my-cluster
# Run a one-off taskaws ecs run-task \ --cluster my-cluster \ --task-definition my-web-app \ --launch-type FARGATE \ --network-configuration "awsvpcConfiguration={subnets=[subnet-abc],securityGroups=[sg-abc],assignPublicIp=ENABLED}"
# List running tasksaws ecs list-tasks --cluster my-cluster
# Describe a serviceaws ecs describe-services \ --cluster my-cluster \ --services my-service