Clusters

A cluster is the logical boundary that groups your tasks and services.

A cluster is a namespace for your workloads. It does not cost anything by itself — it simply groups tasks, services, and (for EC2) container instances.

Common patterns

  • One cluster per environment: dev, staging, prod.
  • One cluster per team or bounded context.

With Fargate, a cluster is almost entirely virtual — there are no servers to see inside it.

Example

Example · bash
# Create a cluster (Fargate-ready by default)
aws ecs create-cluster --cluster-name prod

# Inspect it
aws ecs describe-clusters --clusters prod

When to use it

  • A platform team creates separate ECS clusters for dev, staging, and production so workloads are fully isolated with distinct IAM boundaries.
  • An SRE team enables Container Insights on the production cluster to get per-task CPU and memory metrics in CloudWatch automatically.
  • A FinOps engineer lists all clusters and their running task counts to identify idle clusters that can be deleted.

More examples

Create Cluster with Container Insights

Creates an ECS cluster with Container Insights enabled so task-level CPU and memory metrics are automatically sent to CloudWatch.

Example · bash
aws ecs create-cluster \
  --cluster-name prod-cluster \
  --settings name=containerInsights,value=enabled

List All Clusters and Task Counts

Fetches all clusters in the account and displays each cluster's name alongside its running and pending task counts.

Example · bash
aws ecs describe-clusters \
  --clusters $(aws ecs list-clusters --query 'clusterArns[]' --output text) \
  --query 'clusters[*].{name:clusterName,running:runningTasksCount,pending:pendingTasksCount}' \
  --output table

Delete an Empty Cluster

Safely verifies that no tasks are running in an old cluster before deleting it to avoid disrupting workloads.

Example · bash
# Verify no running tasks first
aws ecs list-tasks --cluster old-cluster

# Then delete
aws ecs delete-cluster --cluster old-cluster

Discussion

  • Be the first to comment on this lesson.