Skip to Content
Asterrr's Handbook
2 · New solutions

Containers on AWS

ECS, EKS, Fargate and ECR compared, with task networking, IAM roles, placement, scaling and the private-subnet endpoints that image pulls need.

Exam tasks: 2.5 (choose compute and container platforms), 4.3 and 4.4 (modernize to containers), 3.3

The decision: do you need Kubernetes specifically, and do you want to manage the instances that run the containers? Those two answers pick between ECS, EKS, Fargate and EC2 capacity.

AWS CloudAWS RegionVPC, private subnetsschedulespull imagesFargate tasksand podsEC2 containerinstancesVPC endpointsAmazon ECRECSEKS
Orchestrators on the left, capacity in the middle, and the registry and network plumbing around them.
awsvpc
The only ECS network mode on Fargate, giving each task its own ENI and security group
20 GiB
Default Fargate task ephemeral storage, configurable up to 200 GiB
3 endpoints
ECR pulls from private subnets need ecr.api, ecr.dkr and the S3 gateway endpoint
2 min
Warning before Fargate Spot reclaims capacity
3 AZs
EKS control plane spreads across three Availability Zones

Choosing the platform

ECSEKSFargateLambda
What it isAWS-native orchestratorManaged Kubernetes control planeServerless capacity for ECS or EKSFunctions
Pick it whenYou want the simplest AWS-native container serviceKubernetes tooling or portability is requiredYou do not want to manage instancesShort, event-driven work
You manageTasks, and instances unless FargatePods, and nodes unless Fargate or Auto ModeTask definitions onlyCode
Runs on-premisesECS AnywhereEKS Anywhere and hybrid nodesNoNo
LimitsAWS onlyKubernetes expertiseNo GPUs, no privileged containers, no host network15 minutes

Exam signal

"Portable, existing Kubernetes manifests, Helm charts" means EKS. "Run containers with the least operational effort" means ECS or EKS on Fargate. "Need GPUs, DaemonSets or custom AMIs" means EC2 capacity, managed by EKS Auto Mode or Karpenter if you want less work.

ECS building blocks

TermMeaning
Task definitionThe blueprint: images, CPU and memory, ports, roles, log driver and secrets
TaskOne running instance of a task definition, for a batch job or a one-off run
ServiceKeeps a desired number of tasks running, replaces failed ones and registers them with a load balancer
ClusterThe logical group of capacity
Capacity providerLinks a cluster to an Auto Scaling group, Fargate or Fargate Spot
  • A service uses the replica strategy (a number of tasks) or daemon (one per instance, EC2 only).
  • Placement strategies apply on EC2 capacity: spread across an attribute such as AZ, binpack to pack tight and save instances, and random. Constraints such as distinctInstance keep tasks apart. Fargate spreads across AZs and ignores these.
  • Rolling updates use minimumHealthyPercent and maximumPercent. The deployment circuit breaker stops and rolls back a deployment whose tasks keep failing to start.
  • Service auto scaling adds tasks by target tracking on CPU, memory or ALB requests per target. Capacity provider managed scaling adds instances when tasks cannot be placed.
  • Service Connect and Cloud Map give services stable names. See compute and containers.

ECS networking, roles and capacity

Network modes

ModeHow it worksUse it whenLimits
awsvpcEach task gets its own ENI and private IPYou want per-task security groups and VPC flow logs per task. Required on FargateENIs per instance limit density; turn on ENI trunking
bridgeDocker's virtual bridge on the host; container ports map to host portsEC2 launch type, many tasks per host with dynamic host ports behind an ALBSecurity groups apply to the host, not the task
hostContainers share the host's network directlyMaximum network performanceTwo tasks can't use the same port on one host
noneNo external networkingBatch jobs that need no networkNo connectivity at all

Per-task security groups

Only awsvpc gives each task its own security group. In bridge or host mode, every task on an instance shares the instance's security groups, so you can't isolate one service's traffic from another on the same host.

IAM roles

  • Task execution role: used by the ECS agent to pull images from ECR, write logs to CloudWatch and fetch secrets from Secrets Manager or Parameter Store for the task definition.
  • Task role: used by your application code to call AWS APIs (read S3, write DynamoDB). Give each task definition its own least-privilege role.
  • Container instance role (EC2 launch type only): lets the agent register the instance with the cluster. Don't give application permissions here, because every task on the host could use them.

On EKS, the equivalent of a task role is EKS Pod Identity or IAM roles for service accounts (IRSA).

Capacity

  • Capacity providers attach Auto Scaling groups or Fargate and Fargate Spot to a cluster, with weights and a base, so a service can run a baseline on Fargate and burst onto Fargate Spot.
  • Fargate Spot suits interruption-tolerant tasks and gives a two-minute warning before reclaiming capacity.
  • EKS Auto Mode and Karpenter manage EKS worker nodes for you when Fargate's limits (no GPUs, no DaemonSets) rule it out.

Fargate

  • You choose a CPU and memory combination for the task. AWS runs it on isolated capacity, and each task has its own kernel boundary.
  • Every task uses awsvpc, so give each its own security group and keep tasks in private subnets with the endpoints below.
  • Fargate Spot (ECS) is discounted and interruptible, with a two-minute warning. Run it for stateless, retryable work.
  • Not supported: GPUs, privileged mode, host networking and DaemonSets-style one-per-node workloads.
  • Charges are per vCPU-second and GB-second from image pull to task stop.

EKS

TopicWhat to know
Control planeManaged, spread across three AZs, with the API server behind a load balancer. You never see the control plane instances
NodesManaged node groups, self-managed nodes, Fargate profiles, or EKS Auto Mode which also manages the node lifecycle
Pod networkingThe VPC CNI gives each pod a VPC IP address, so large clusters can exhaust subnet IPs. Fix with prefix delegation, custom networking or IPv6
IngressThe AWS Load Balancer Controller creates ALBs for Ingress and NLBs for Services
Pod permissionsEKS Pod Identity or IRSA. Never put application permissions on the node role
Cluster accessAccess entries map IAM principals to Kubernetes permissions, replacing the old aws-auth ConfigMap
ScalingHPA for pods, and Karpenter or Cluster Autoscaler for nodes
VersionsA Kubernetes version gets standard support for a limited period, then extended support at an added cost

Running out of pod IPs

A cluster that cannot start new pods while nodes have free CPU and memory is often out of subnet IP addresses, because the VPC CNI assigns a VPC IP to every pod. The fix is more address space for pods, not bigger nodes.

Amazon ECR

  • Private registries per account and Region, with image scanning (basic, or enhanced through Amazon Inspector), lifecycle policies to expire old images, immutable tags and encryption with KMS.
  • Replication copies repositories across Regions and accounts, and a pull-through cache mirrors upstream public registries.
  • Tasks in private subnets with no NAT need the ecr.api and ecr.dkr interface endpoints, the S3 gateway endpoint (image layers come from S3) and a CloudWatch Logs endpoint if the tasks log there.

Pulls fail in a private subnet

Two ECR interface endpoints are not enough. The image layers are stored in S3, so without the S3 gateway endpoint, or a NAT, the pull stalls after the manifest download.

Scenarios

Scenario · choose 2
A company runs a web service as ECS tasks on Fargate in private subnets with no NAT gateway, to avoid NAT costs. New tasks stay in PROVISIONING and then fail with a CannotPullContainerError for an image in Amazon ECR. Which TWO changes fix this? Choose TWO.
Scenario
A team has 40 Kubernetes microservices described in Helm charts and wants minimal changes to its deployment process while no longer patching control plane or worker instances. Which choice fits best?

Further reading

On this page