Amazon ECS

Also known as: Amazon Elastic Container Service · Elastic Container Service

On this page 7

Amazon ECS (Amazon Elastic Container Service) is a fully managed container orchestration service from AWS that places, runs, monitors and scales containers across a pool of compute capacity. In the world of containers and cloud infrastructure, it occupies the same role as Kubernetes or Docker Swarm, but with an AWS-specific control plane that the customer never installs, patches or pays for separately.

Elastic Container Service launched in 2015 and remains one of the most widely used ways to run container workloads on AWS. Its design favors deep integration with native AWS services such as IAM, Elastic Load Balancing, CloudWatch and VPC networking over portability, which is the central trade-off teams weigh when they choose it.

How Amazon ECS schedules and runs containers

Amazon ECS works by matching a declarative description of containers against available capacity and keeping the actual state equal to the desired state. The regional control plane is operated entirely by AWS; customers interact with it through the console, the CLI, the API or infrastructure-as-code tools such as AWS CloudFormation and Terraform.

The core building blocks are few and strictly hierarchical. A task definition is a versioned JSON document that lists one or more container images, CPU and memory reservations, port mappings, environment variables, secrets, log drivers and the IAM role the containers assume. A task is a running instance of that definition, and a service keeps a specified number of tasks alive, replaces failed ones and registers them with a load balancer.

The following table summarizes the main objects and what each one controls.

ObjectWhat it representsTypical scope
ClusterLogical grouping of capacity and servicesOne per environment or team
Task definitionImmutable, versioned container blueprintOne per application component
TaskRunning copy of a task definitionSeconds to months of runtime
ServiceLong-running controller for a desired task countWeb APIs, workers, daemons
Capacity providerLink between a cluster and its compute sourceFargate, Fargate Spot or Auto Scaling group
Container agentProcess on EC2 hosts that reports state and starts tasksOne per container instance
Core objects in Amazon ECS

When a service needs a new task, the scheduler evaluates placement constraints and strategies such as spread across Availability Zones, binpack on memory or random placement. It then asks the chosen capacity to pull the image from a container registry, usually Amazon ECR, and start the containers through the container runtime.

Launch types: EC2, Fargate and external capacity

The launch type determines who manages the servers beneath the containers. With the EC2 launch type, tasks run on virtual machines in the customer account that carry the ECS container agent; the customer chooses instance families, applies operating system patches and pays for the instances whether they are full or idle. With AWS Fargate, each task receives its own isolated micro virtual machine and billing follows the vCPU and memory requested per second.

A third option, ECS Anywhere, registers on-premises or other-cloud servers as external instances so the same control plane can schedule tasks outside AWS regions. The comparison below shows the practical differences.

Launch typeServer managementBilling basisBest fit
EC2Customer patches and scales instancesPer instance hourSteady, dense or GPU workloads
FargateNone; AWS manages hostsPer task vCPU and GB-secondVariable load, small teams
Fargate SpotNone; tasks can be interruptedDiscounted spare capacityBatch and fault-tolerant jobs
External (ECS Anywhere)Customer owns hardwarePer managed instance hourHybrid and edge sites
Comparison of ECS launch types

Networking follows the launch type as well. The awsvpc network mode, mandatory on Fargate, gives every task its own elastic network interface and private IP address, so security groups apply per task rather than per host. The older bridge and host modes share the instance network stack and remain useful on EC2 when interface limits would otherwise cap task density.

Amazon ECS compared with Kubernetes and other orchestrators

Amazon ECS differs from Kubernetes mainly in scope, portability and operational effort. Kubernetes, offered on AWS as Amazon EKS, exposes a large open API with custom resources, operators and a vast ecosystem, while ECS offers a deliberately smaller set of concepts that map directly to AWS primitives.

OptionControl plane costPortabilityLearning curve
Amazon ECSNo separate chargeAWS only, plus ECS AnywhereLow to moderate
Amazon EKSHourly fee per clusterHigh; standard Kubernetes APIHigh
Docker SwarmSelf-hostedHigh; any Docker hostLow
Docker ComposeNone; single hostHigh, but not clusteredVery low
How ECS relates to neighboring orchestration options

Teams that already think in IAM roles, target groups and CloudWatch alarms usually reach production faster on ECS. Teams that need multi-cloud portability, Helm charts, service meshes beyond AWS App Mesh successors or fine-grained scheduling extensions tend to choose Kubernetes despite its higher operational burden.

Configuring services, scaling and deployments

Production ECS services rely on a handful of settings that decide availability and cost. Service Auto Scaling adjusts the desired count through target tracking on metrics such as average CPU, memory or requests per target, while cluster auto scaling with capacity providers adds or removes EC2 instances to fit pending tasks.

Deployments default to a rolling update controlled by minimum healthy percent and maximum percent. A common pair is 100 and 200, which starts new tasks before stopping old ones. The deployment circuit breaker can roll back automatically when new tasks fail health checks, and blue/green deployments through AWS CodeDeploy shift load balancer traffic between two target groups.

The decision table below maps common situations to recommended configurations.

SituationRecommended choiceReason
Public HTTP API with spiky trafficFargate with target tracking on request countScales tasks without managing hosts
Machine learning inference on GPUsEC2 launch type with GPU instancesFargate offers no general GPU support
Nightly batch processingFargate Spot or EC2 Spot capacity providerLarge savings on interruptible work
Strict change controlBlue/green deployment with CodeDeployInstant rollback by shifting traffic
Service-to-service callsECS Service ConnectBuilt-in discovery and traffic metrics
Choosing an ECS configuration

Secrets belong in AWS Secrets Manager or Systems Manager Parameter Store, referenced from the task definition, never baked into a container image. Two IAM roles must be kept distinct: the task execution role lets the agent pull images and write logs, while the task role grants the application its own AWS permissions.

Limitations and common mistakes

The most significant limitation of Amazon ECS is vendor lock-in: task definitions, service definitions and the scheduler have no direct equivalent outside AWS, so migrating to another cloud means rewriting deployment artifacts even though the container images themselves stay portable under Open Container Initiative formats.

  • Oversized task reservations waste money on Fargate, where billing follows requested rather than consumed CPU and memory.
  • Missing health check grace periods cause slow-starting applications to be killed in a restart loop.
  • Using the latest image tag makes task definitions non-reproducible; immutable tags or image digests prevent drift.
  • Single Availability Zone placement turns a zone outage into a full service outage.
  • Exhausted IP addresses in small subnets block awsvpc tasks from starting, a frequent surprise in dense clusters.

Fargate also imposes fixed CPU and memory combinations, ephemeral storage limits and no privileged containers, which rules out some low-level networking or security agents that EC2 hosts can run.

In everyday language

Think of Amazon ECS as a dispatcher for packaged software. A container is a sealed box holding an application and everything it needs. ECS reads instructions that say which boxes to run, how many copies, and how much power each one gets, then finds space for them on Amazon computers and keeps them running.

If a copy crashes, ECS starts a new one. If many visitors arrive, it can add copies, and when the crowd leaves, it removes them. The customer can let Amazon handle the computers completely, or keep control of the machines. The key takeaway: ECS keeps containers running at the right scale without the team building its own scheduling system.

Seen in the real world

A mid-sized online retailer runs its storefront API, a checkout service and an image-resizing worker on Amazon ECS. The API and checkout services run on Fargate across three Availability Zones behind an Application Load Balancer, each starting with four tasks of 1 vCPU and 2 GB of memory and scaling on requests per target up to 40 tasks during holiday sales.

The image worker reads jobs from a queue and runs on Fargate Spot, because an interrupted resize can simply be retried. Deployments use rolling updates with the circuit breaker enabled, so a faulty release that fails health checks is rolled back within minutes. The outcome is a platform that absorbs a tenfold traffic peak with no servers to patch and a small operations team focused on application code.