# Amazon ECS with Fargate

> Run containers on AWS without managing servers or Kubernetes using ECS task definitions, services and Fargate behind an ALB. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/cloud-engineer/ecs-fargate
Last updated: 2026-11-28

Run containers on AWS without managing servers or Kubernetes using ECS task definitions, services and Fargate behind an ALB.

Intermediate · about 6 hours · difficulty 3/5

Learn first: [Docker and Container Images](https://www.internhack.in/roadmaps/tracks/cloud-engineer/docker), [Elastic Load Balancing: ALB and NLB](https://www.internhack.in/roadmaps/tracks/cloud-engineer/load-balancers), [VPC Endpoints and PrivateLink](https://www.internhack.in/roadmaps/tracks/cloud-engineer/vpc-endpoints)

**Amazon ECS** is AWS's own container orchestrator. With **Fargate** you do not manage any EC2 instances: you say how much CPU and memory a task needs and AWS runs it. For most teams that do not already need Kubernetes, ECS on Fargate is the fastest path to production containers. Azure Container Apps and Google Cloud Run fill a similar role.

### Core concepts

- **Task definition**: the blueprint (image, CPU, memory, ports, environment, secrets, log configuration, task role).
- **Task**: a running copy of a task definition.
- **Service**: keeps N tasks running, replaces failed ones and registers them with an ALB target group.
- **Cluster**: a logical grouping of services.
- **Capacity providers**: Fargate, Fargate Spot (cheaper, interruptible) or your own EC2 Auto Scaling groups.

### Networking and security

- Use **awsvpc** networking: every task gets its own ENI and security group.
- Run tasks in private subnets; the ALB sits in public subnets.
- **Task role** for app permissions, **task execution role** for pulling images and reading secrets.
- Inject secrets from Secrets Manager or Parameter Store, never plain environment variables in the task definition.

### Deployments and scaling

- **Rolling updates** with the deployment circuit breaker to auto-roll back failed releases, or blue/green with CodeDeploy.
- **Service auto scaling** on CPU, memory or ALB request count.
- **ECS Exec** to get a shell inside a running task for debugging.

### Pitfalls

- Tasks stuck in PENDING because private subnets have no route to ECR (add NAT or endpoints).
- Mixing up the task role and the execution role.

You are ready to move on when you can deploy a containerized API to ECS Fargate behind an ALB with logs in CloudWatch and roll out a new version with zero downtime.

## Key concepts

- **Task definitions**
- **Services and clusters**
- **Fargate and Fargate Spot**
- **awsvpc networking**
- **Task role vs execution role**
- **Secrets injection**
- **Deployment circuit breaker**
- **Service auto scaling**
- **ECS Exec**
- **AWS App Runner**: Even simpler, fully managed container hosting

## Other options for this step

- [Amazon EKS (Managed Kubernetes)](https://www.internhack.in/roadmaps/tracks/cloud-engineer/eks): Run Kubernetes on AWS with EKS: managed node groups or Fargate, IAM integration, the AWS Load Balancer Controller and add-ons.

## Mini project

Deploy your containerized API to ECS Fargate with 0.25 vCPU tasks behind an ALB, logs in CloudWatch, and a secret from Secrets Manager. Push a new image tag and watch the rolling deployment. Fargate and ALBs are not free, so do this in one sitting (cost should stay to a few rupees), then scale the service to zero and delete the service, cluster and ALB.

## Check yourself

Your ECS task fails with 'unable to pull secrets or registry auth'. Which role is misconfigured, and what else might be missing in the network?

## Free resources

- [Amazon ECS documentation](https://docs.aws.amazon.com/ecs/) (AWS)
- [AWS Fargate](https://aws.amazon.com/fargate/) (AWS)
- [Amazon ECS best practices guide](https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/intro.html) (AWS)

Previous: [Docker and Container Images](https://www.internhack.in/roadmaps/tracks/cloud-engineer/docker) · Next: [Amazon EKS (Managed Kubernetes)](https://www.internhack.in/roadmaps/tracks/cloud-engineer/eks)

## More in Containers on AWS

- [Docker and Container Images](https://www.internhack.in/roadmaps/tracks/cloud-engineer/docker)
- [Amazon ECS with Fargate](https://www.internhack.in/roadmaps/tracks/cloud-engineer/ecs-fargate)
- [Amazon EKS (Managed Kubernetes)](https://www.internhack.in/roadmaps/tracks/cloud-engineer/eks)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cloud Engineer (AWS) Roadmap](https://www.internhack.in/roadmaps/tracks/cloud-engineer)
