The Basics

Amazon ECS, the Elastic Container Service, is an Amazon alternative to Docker Swarm, Kubernetes, and HashiCorp Nomad. Amazon aims to make ECS as simple as possible to reduce the complexity of deploying container-based workloads. Under the hood, ECS runs docker on EC2 instances.

Primary Use Cases

  • Maximize EC2 compute resource usage
  • Scalable deployment of container workloads
  • Scalable batch processing

Uncommon and Unsuitable Use Cases

  • Simple web application or website hosting.
  • Consider Amazon S3 or AWS Amplify instead.

Amazon ECS contains these core layers.

ECS Overview

Review Amazon Elastic Container Service template snippets for a big-picture view of CloudFormation YAML resources.


ECS components optionally depend on EC2, Auto Scaling, Load Balancers, and CloudWatch to operate depending on your overall deployment strategy. Using Fargate simplifies deployment further by removing components from your software architecture.

I will now summarize each ECS component. Where applicable, a link to CloudFormation resource documentation is present.


A Cluster is a logical grouping of Tasks or Services running on an EC2 instance, otherwise known as a Container Instance.

Example: fancy-web-application-cluster

The primary responsibility of an Amazon ECS Cluster is managing infrastructure for your Tasks.


Describe a cluster with this command.

aws ecs describe-clusters --cluster fancy-web-application-cluster

Container Instance

An Amazon ECS container instance is an EC2 instance running an Amazon ECS container agent registered into an Amazon ECS cluster.

The primary responsibility of an Amazon ECS container instance is computing resources for your ECS cluster.

Describe container instances with this command.

aws ecs describe-container-instances --cluster fancy-web-application-cluster


Manages the desired state of your tasks. It defines the number of Tasks to run, autoscaling, and load-balancing strategies. It can optionally work with an Amazon load balancer.

Example: fancy-web-application-service

The primary responsibility of an Amazon ECS Service is keeping your Cluster healthy.


Describe an ECS Service with this command.

aws ecs describe-services --services fancy-web-application-service

Container Agent

Allows container instances to connect to your Cluster.

The Amazon ECS container agent is primarily responsible for managing containers on Amazon ECS.

The ECS container agent runs on each Container instance within a cluster and sends telemetry data about that instance’s tasks and resource utilization to the ECS service.

The Amazon ECS container agent ships with ECS-optimized AMIs, but you can also install it on any Amazon EC2 instance that supports the Amazon ECS specification.

Task Definition

I’m using an example webserver task definition provided by AWS for reference. The Task Definition parameters documentation provides a more comprehensive overview.

A Task Definition is a core ECS concept. Describe a Task Definition using a JSON file.

A Task Definition is a collection of container configurations. The Task Definition allows you to specify which Docker image to use, which ports to expose, how much CPU and memory to allocate, how to collect logs, and define environment variables. A task may need one container, while others may require two or more containers.


A Task Definition includes these properties.


A Task Definition family is a name for a group of versioned containers.

Examples: fancy-web-api, fancy-web-server


Launch types

A Task Definition’s Launch types tell Amazon which environment to deploy containers.

Possible values are EC2, Fargate, and External.

Example: EC2



A Task Definition’s hard limit of CPU units allocated to a task.

A value of 1024 represents one vCPU.

Example: 1024



A hard limit of memory (in MiB) allocated to the task.

Example: 1024 ( 1 GB )


Container Definition

An array of up to ten container definitions. A Container Definition is the core component of a Task Definition.

The container definition’s CPU and memory allocations are separate from the Task Definition’s properties.



A name for a container.

The Name property has a maximum length of 255 characters. Use the name of the container to form links between containers.

Example: Nginx



Defines the container that starts with the task definition using a docker repository and tag name.

Images in the Docker Hub registry are available by default. Use the repository-url/image:tag or repository-url/image@digest format for container registries outside Docker Hub.

Example: debian:latest,



The amount (in MiB) of memory allocated to the container. Use the memoryReservation property to set the minimum required memory for your container. Leave the memory property blank unless you need your container to terminate when memory consumption exceeds the defined limit.

Example: memory: 1024, memoryReservation: 128


Port Mappings

Optional port mappings allow containers to access ports on the host instance to send or receive traffic.

Example: 8080


Describe a task definition with this AWS CLI command.

aws ecs describe-task-definition


I introduced Task Definition LaunchTypes previously. A choice of LaunchType fundamentally changes your architecture. Fargate simplifies your architecture and, depending on requirements, can be cheaper than an ECS LaunchType architecture. Fargate controls the underlying infrastructure, while ECS LaunchType requires you to manage the underlying infrastructure.

Per Amazon’s comparison of Fargate VS. EC2 cost optimization.

Fargate has an 87% saving over an EC2 equivalent when the EC2 memory and vCPU reservation rate are at 6.25% and 12.5%, respectively.

On-Demand Price Difference

Best Practices

Learn ECS - Beyond The Basics

Other Learning