Skip to content
Back to Cloud Services

AWS ECS Container Service

Run Docker containers on managed EC2 clusters or Fargate serverless compute.

AWSIntermediate

Why

ECS runs Docker without Kubernetes complexity — task definitions, services, and scheduling handled. Fargate mode removes server management entirely.

Cheaper than EKS for simple workloads.

When

Use ECS for Docker workloads without K8s needs — web APIs, background workers, scheduled tasks. Use EKS when you need K8s ecosystem (Helm, operators).

How

1. Cluster — aws ecs create-cluster, EC2 or Fargate launch type 2. Task definition — JSON spec of container (image, cpu, memory, ports, env) 3. Service — runs N tasks, integrates with ALB, auto-scaling 4. Fargate — no EC2 management, pay per vCPU/GB-second 5. EC2 mode — manage ASG of EC2, cheaper for steady load 6. Logging — awslogs driver → CloudWatch Logs 7. Secrets — store in Secrets Manager/SSM, reference in task def 8. Service Connect — built-in service discovery + load balancing

Example

# Task definition for Fargate aws ecs register-task-definition --cli-input-json '{ "family": "web-app", "networkMode": "awsvpc", "requiresCompatibilities": ["FARGATE"], "cpu": "512", "memory": "1024", "containerDefinitions": [{ "name": "app", "image": "123.dkr.ecr.us-east-1.amazonaws.com/app:v1", "portMappings": [{"containerPort": 80}], "logConfiguration": {"logDriver": "awslogs", "options": {"awslogs-group": "/ecs/app"}} }] }' # Run as service with ALB aws ecs create-service \ --cluster prod --service-name web \ --task-definition web-app:1 \ --desired-count 2 --launch-type FARGATE \ --network-configuration awsvpcConfiguration={subnets=[subnet-1],securityGroups=[sg-1]} \ --load-balancers targetGroupArn=arn:aws:elasticloadbalancing:...,containerName=app,containerPort=80

Common Problems

  • ⚠Task stops with no logs — check CloudWatch log group exists and execution role has logs permission
  • ⚠Image pull fails — ensure task execution role has ecr:GetRepositoryPolicy permission
  • ⚠Fargate cold start 5-10s — for latency-sensitive, keep min capacity > 0

Best Practices

  • ✓Use Fargate for low ops — no EC2 patching, pay per use, scale to zero
  • ✓Store secrets in Secrets Manager — auto-rotation, IAM-controlled, no plaintext in task def
  • ✓Use ECS Service Connect — built-in service mesh-lite, no Istio needed for simple cases

FAQ

What is AWS ECS Container Service and what problem does it solve?

Run Docker containers on managed EC2 clusters or Fargate serverless compute. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with AWS ECS Container Service in 5 minutes?

Two steps to run it: (1) Cluster — aws ecs create-cluster, EC2 or Fargate launch type; (2) Task definition — JSON spec of container (image, cpu, memory, ports, env). Validate on the free tier first, then wire into production.

What is the #1 pitfall with AWS ECS Container Service?

The most frequent issue is: Task stops with no logs — check CloudWatch log group exists and execution role has logs permission. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for AWS ECS Container Service?

Best practices for AWS ECS Container Service include: Use Fargate for low ops — no EC2 patching, pay per use, scale to zero; Store secrets in Secrets Manager — auto-rotation, IAM-controlled, no plaintext in task def; Use ECS Service Connect — built-in service mesh-lite, no Istio needed for simple cases. The first one — "Use Fargate for low ops — no EC2 patching, pay per use, scale to zero" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with AWS ECS Container Service?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most AWS ECS Container Service options offer a free tier — validate within free quota before scaling.