DEV Community

Cover image for AWS ECS Basics and Tips
Guille Ojeda for AWS Community Builders

Posted on • Originally published at newsletter.simpleaws.dev

AWS ECS Basics and Tips

Note: This content was originally published at the Simple AWS newsletter. Understand the Why behind AWS Solutions. Subscribe for free! 3000 engineers and tech experts already have.

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.

Recommended Resources for ECS

Learn how to deploy an application on ECS, with high availability, scalability and best practices.

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:


Understand the Why behind AWS Solutions.
Join over 3000 devs, tech leads, and experts learning how to architect cloud solutions, not pass exams, with the Simple AWS newsletter.

  • Real-world scenarios
  • The Why behind solutions
  • How to apply best practices

Subscribe for free!

If you'd like to know more about me, you can find me on LinkedIn or at www.guilleojeda.com

Top comments (0)