• Simple AWS
  • Posts
  • Elastic Container Service Basics and Tips

Elastic Container Service Basics and Tips

A quick overview of ECS, a pricing analysis and 3 workshops.

Elastic Container Service (ECS) is basically a container orchestrator (like Kubernetes) but done by AWS. You pick a Docker app, set parameters like CPU and memory, set up an EC2 Auto Scaling Group or use Fargate (serverless, you pay per use), and ECS handles launching all your containers, scaling them and managing networking, logging, monitoring, etc.

Basic Elements of Elastic Container Service

  • Cluster: It's a container for everything. It defines where the capacity comes from (EC2 or Fargate) and contains all the other resources.

  • Task Definition: It's a blueprint for Tasks. You define a Task Definition, and ECS creates Tasks as instances of that Task Definition (like objects and classes in OOP, this one's the class). The Task Definition is where you set things like:

    • The Docker image

    • CPU and memory

    • Launch type (EC2 or Fargate)

    • Logging configuration

    • Volumes

    • The IAM role

  • Task: An instance of a Task Definition. This is basically your container running, plus all the ECS configurations associated with it. The ECS Task Scheduler handles creating the tasks, placing them and creating new ones as needed.

  • Service: A grouping of Tasks (with the same Task Definition), with a Load Balancer in front of them.

ECS vs Kubernetes Comparison

ECS is easier than Kubernetes. If you're starting from scratch, don't have anything in Kubernetes yet and don't plan to move away from AWS, going with ECS will save you a non-trivial amount of headaches.

Also, ECS is free. You only pay for the EC2 instances or Fargate capacity and the Load Balancers. In contrast, an EKS cluster (AWS's managed service for Kubernetes) costs $72/month.

If you already have some stuff on Kubernetes (for example, some Helm charts you want to use) or are proficient in Kubernetes, you can use EKS.

Choosing Between Fargate and EC2 for ECS

If your workload is unpredictable, you can use Fargate with ECS. Fargate is a serverless capacity provider, where you only pay for the capacity your containers are actually consuming. A huge advantage is that it scales much faster than EC2: You don't need to wait for instances to launch, just for the new container to start. It is more expensive than EC2 though, per vCPU hour.

For reference, 2 tasks running continuously, each with 1 vCPU and 4 GB of memory, cost $85/month in Fargate and $53/month on EC2. With both EC2 and Fargate you can purchase Savings Plans to reduce costs. In the case of EC2 you can also acquire Reserved Instances. You can find a more complete analysis here.

Here's a book I wrote that'll teach you how to deploy an application on ECS, with high availability, scalability and best practices.

And if you prefer video courses, I turned that same book into a 10-hour video course called Deploying on AWS.

AWS Copilot CLI is a tool that lets you deploy production-ready, scalable services on AWS from a Dockerfile in one command.

Want to learn how to use ECS? Check out:

Thank you for reading! See ya on the next issue.

Join the conversation

or to participate.