AWS ECS Basics and Tips
Tags: aws, containers, cloud, cloudcomputing
Published: 2023-08-26 14:45:00

Note: This content was originally published at the **[Simple AWS newsletter](https://www.simpleaws.dev?utm_source=blog&utm_medium=dev.to)**. 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](https://aws.amazon.com/blogs/containers/theoretical-cost-optimization-by-amazon-ecs-launch-type-fargate-vs-ec2/).

## Recommended Resources for ECS

Learn [how to deploy an application on ECS](https://downloads.simpleaws.dev/b/nodejsonaws?utm_source=blog&utm_medium=dev.to), with high availability, scalability and best practices.

[AWS Copilot CLI](https://github.com/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:

* [An introductory workshop](https://catalog.us-east-1.prod.workshops.aws/workshops/8c9036a7-7564-434c-b558-3588754e21f5/en-US)

* [The extremely popular ECS workshop](https://ecsworkshop.com)

* [A workshop on CI/CD for ECS](https://catalog.us-east-1.prod.workshops.aws/workshops/869f7eee-d3a2-490b-bf9a-ac90a8fb2d36/en-US)

* [The Containers from the Couch YouTube channel](https://www.youtube.com/containersfromthecouch). At re:Invent 2021 I got a pillow from them!


---

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](https://www.simpleaws.dev?utm_source=blog&utm_medium=dev.to).

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

[Subscribe for free!](https://www.simpleaws.dev?utm_source=blog&utm_medium=dev.to)

<iframe src="https://embeds.beehiiv.com/1c90a8a9-57b7-4a3f-ac56-5f05d0121f72?slim=true" style="margin:0;border-radius:0px;background-color:transparent;display:block;margin-left:auto;margin-right:auto" height="55px"></iframe>

If you'd like to know more about me, you can find me [on LinkedIn](https://www.linkedin.com/in/guilleojeda/) or at [www.guilleojeda.com](https://www.guilleojeda.com?utm_source=blog&utm_medium=dev.to)