# Amazon ECS and Fargate

> AWS runs your containers; with Fargate you never see the servers at all.

- Level: Intermediate
- Topics: AWS, Cloud
- URL: https://tidbit.legios.com.ar/amazon-ecs-and-fargate/
- In Spanish: [Amazon ECS y Fargate](https://tidbit.legios.com.ar/es/amazon-ecs-and-fargate/)

**Amazon ECS** (Elastic container Service) is the AWS service that runs containers for you. You write a **task definition**: which container image to use, how much CPU and memory it needs, which ports it opens, which environment variables it gets. Then you create a **service**: 'keep three copies of this task running behind this load balancer', and ECS makes sure three are always alive, replacing any that die.

Where do those containers physically run? Two options. With the EC2 launch type you keep a fleet of Amazon EC2 instances and ECS places tasks on them; you patch and size the machines. With **Fargate** there is no machine to manage: you say 'this task needs 1 vCPU and 2 GB', AWS finds the capacity, starts the container and bills you per second while it runs.

Example: a Python API packaged as a Docker image and pushed to Amazon ECR, the AWS image registry. An ECS service on Fargate runs two copies in private subnets of a VPC with a load balancer in front; autoscaling adds copies when CPU stays above 70%. Shipping a new version means pushing a new image tag and letting ECS roll it out copy by copy.

ECS is the simpler, AWS-native way to run containers. Amazon EKS is the choice when a team already works with Kubernetes and wants to keep that toolset.

## An analogy

A food court. ECS is the manager who guarantees your stall is always open and staffed. With Fargate you also stop renting floor space: you say how big a stall you need and it appears, and you pay only while it is open.

## Keep in mind

- A task definition is the recipe; a service keeps N copies of it running and healthy.
- Fargate removes servers entirely: you pay per vCPU and GB for the seconds a task runs.
- Images usually live in Amazon ECR, the AWS container registry.
- ECS plugs into IAM, load balancers and CloudWatch without extra setup.

## Go deeper

- [What is Amazon ECS? (official docs)](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html)
- [AWS Fargate product page](https://aws.amazon.com/fargate/)

## Related terms

- [Container](https://tidbit.legios.com.ar/container/): A sealed box with a program and everything it needs to run anywhere.
- [CPU](https://tidbit.legios.com.ar/cpu/): The chip that runs your programs, one instruction after another, very fast.
- [Port](https://tidbit.legios.com.ar/port/): The numbered door on a computer that says which program a connection is for.
- [Environment variables](https://tidbit.legios.com.ar/environment-variables/): Named settings a program reads from outside its code, like where its database lives.
- [Load balancer](https://tidbit.legios.com.ar/load-balancer/): The traffic cop that spreads incoming requests across many servers.
- [Amazon EC2](https://tidbit.legios.com.ar/amazon-ec2/): Virtual computers you rent by the hour, in any size, and switch off when done.
- [Python](https://tidbit.legios.com.ar/python/): A popular programming language known for being easy to read and quick to write.
- [API](https://tidbit.legios.com.ar/api/): The menu of things one program lets another program ask for.
