Containers on AWS: Amazon ECR, ECS, Fargate and EKS Explained for Solutions Architects

AWS Solutions Architect 45 min min read Updated: Nov 17, 2026 Intermediate
Containers on AWS: Amazon ECR, ECS, Fargate and EKS Explained for Solutions Architects
Intermediate Topic 4 of 4

Containers Recap

A container packages an app with its dependencies so it runs the same everywhere. AWS gives you a registry to store images, orchestrators to run them, and compute to host them.

text Build image ─► push to ECR (registry) ─► ECS or EKS (orchestrator) ─► runs on Fargate (serverless) or EC2 (your instances) │ behind an ALB, logs to CloudWatch, secrets from Secrets Manager

Amazon ECR

  • Elastic Container Registry: private (and public) Docker/OCI image registry, integrated with IAM
  • Image scanning (basic and enhanced with Inspector) finds vulnerabilities
  • Lifecycle policies delete old images to save cost
  • Replication across Regions and accounts
  • Tag immutability prevents overwriting a tag
bash aws ecr create-repository --repository-name shop-api --image-scanning-configuration scanOnPush=true --image-tag-mutability IMMUTABLE aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com docker build -t shop-api:1.0.0 . docker tag shop-api:1.0.0 123456789012.dkr.ecr.ap-south-1.amazonaws.com/shop-api:1.0.0 docker push 123456789012.dkr.ecr.ap-south-1.amazonaws.com/shop-api:1.0.0

Amazon ECS: Elastic Container Service

ECS is AWS's own container orchestrator. It is simple, deeply integrated with AWS and has no extra control plane fee.

ConceptMeaning
ClusterA logical group of tasks and services
Task definitionThe blueprint (like a Compose file): images, CPU, memory, ports, environment, roles, logging. Versioned
TaskA running copy of a task definition (one or more containers)
ServiceKeeps N tasks running, replaces failed ones, integrates with a load balancer, supports rolling and blue/green deployments, auto scaling
Capacity providerWhere tasks run: Fargate, Fargate Spot, or an EC2 Auto Scaling group
json { "family": "shop-api", "requiresCompatibilities": ["FARGATE"], "networkMode": "awsvpc", "cpu": "512", "memory": "1024", "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole", "taskRoleArn": "arn:aws:iam::123456789012:role/shopApiTaskRole", "runtimePlatform": {"cpuArchitecture": "ARM64", "operatingSystemFamily": "LINUX"}, "containerDefinitions": [{ "name": "api", "image": "123456789012.dkr.ecr.ap-south-1.amazonaws.com/shop-api:1.0.0", "portMappings": [{"containerPort": 8080}], "essential": true, "environment": [{"name": "STAGE", "value": "prod"}], "secrets": [{"name": "DB_PASSWORD", "valueFrom": "arn:aws:secretsmanager:ap-south-1:123456789012:secret:prod/shop/db"}], "logConfiguration": {"logDriver": "awslogs", "options": {"awslogs-group": "/ecs/shop-api", "awslogs-region": "ap-south-1", "awslogs-stream-prefix": "api"}}, "healthCheck": {"command": ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"], "interval": 30, "retries": 3} }] }
RoleUsed byPurpose
Task execution roleECS agent / FargatePull the image from ECR, write logs to CloudWatch, read secrets to inject
Task roleYour application code inside the containerCall S3, DynamoDB, SQS etc. (least privilege per service)
bash aws ecs create-cluster --cluster-name shop aws ecs register-task-definition --cli-input-json file://taskdef.json aws ecs create-service --cluster shop --service-name api --task-definition shop-api --desired-count 3 \ --launch-type FARGATE \ --network-configuration 'awsvpcConfiguration={subnets=[subnet-priv-a,subnet-priv-b],securityGroups=[sg-api],assignPublicIp=DISABLED}' \ --load-balancers targetGroupArn=$TG,containerName=api,containerPort=8080 \ --deployment-configuration 'deploymentCircuitBreaker={enable=true,rollback=true},minimumHealthyPercent=100,maximumPercent=200'
  • awsvpc mode gives each task its own ENI and security group. Required for Fargate
  • The deployment circuit breaker rolls back a bad release automatically
  • Scale services with Application Auto Scaling (target tracking on CPU, memory or ALB requests per target)

Fargate vs EC2 Launch Type

Fargate (serverless)EC2 (you manage nodes)
Servers to manageNoneYou patch and scale the instances
PricingPer vCPU and GB per second the task runsPay for the instances (cheaper at high steady utilization)
ControlLimited (no daemon sets, no GPU on standard Fargate in many cases)Full: GPU, custom AMI, privileged containers, any instance type
Good forMost web apps, APIs, batch, small teams, least operational overheadLarge steady fleets, special hardware, tight cost optimization
Cost savingFargate Spot and Savings Plans (Compute SP)Spot, Reserved, Savings Plans

Amazon EKS: Elastic Kubernetes Service

EKS runs managed Kubernetes. AWS operates the control plane (multi-AZ API servers and etcd). You run workloads on managed node groups (EC2), Fargate profiles, or let EKS Auto Mode manage nodes.

bash eksctl create cluster --name shop --region ap-south-1 --nodegroup-name ng1 \ --node-type m7g.large --nodes 3 --nodes-min 2 --nodes-max 6 --managed aws eks update-kubeconfig --name shop --region ap-south-1 kubectl get nodes
EKS topicWhat to know
Control plane costA per-cluster hourly fee, plus compute for nodes
VersionsKubernetes versions are supported for a limited time. Plan upgrades
Pod permissionsIAM Roles for Service Accounts (IRSA) or EKS Pod Identity give pods temporary AWS permissions without node-wide access
NetworkingThe VPC CNI gives pods VPC IP addresses. Plan subnet sizes (pods use many IPs)
IngressAWS Load Balancer Controller creates ALBs and NLBs from Ingress and Service objects
ScalingHorizontal Pod Autoscaler, Karpenter or Cluster Autoscaler for nodes
Add-onsCoreDNS, kube-proxy, VPC CNI, EBS CSI driver, managed through EKS

Other Container Options

ServiceUse
AWS App RunnerSimplest: give a container image or source repo, get an auto-scaled HTTPS service. Good for small web apps and APIs
AWS Copilot CLICommand-line helper to deploy on ECS
Elastic Beanstalk (Docker)PaaS style deployment including containers
ECS Anywhere / EKS AnywhereRun on your own hardware with AWS tooling
AWS BatchRun batch jobs on Fargate or EC2 and Spot

Which One Should I Choose?

SituationChoice
Team wants the simplest way to run containers with minimal operationsECS on Fargate (or App Runner for very simple apps)
Team already uses Kubernetes, needs portability or the Kubernetes ecosystemEKS
Need GPUs, custom kernels or large steady fleets and cost controlECS or EKS on EC2
Short event-driven functionsLambda
Cost-sensitive fault-tolerant batchFargate Spot or EC2 Spot with AWS Batch
Lift-and-shift of a VM-based appEC2

Practice Tasks

  1. Push a small image to an ECR repository with scan on push
  2. Write a task definition and run it as a Fargate service with 2 tasks behind an ALB
  3. Kill one task and watch the service replace it
  4. Introduce a failing image tag and see the circuit breaker roll back
  5. Compare the monthly cost of 3 Fargate tasks (0.5 vCPU, 1 GB) with one t4g.medium instance using the AWS pricing calculator

Conclusion

ECR stores images, ECS runs them simply with tasks and services, EKS runs managed Kubernetes, and Fargate removes server management. Use task roles for app permissions, execution roles for pulling images and logs, awsvpc networking with ALBs, and choose Fargate for least operations, EC2 for special needs, EKS for the Kubernetes ecosystem.

Quick Summary: ECR scan/lifecycle; ECS cluster/task def/service/capacity provider; task vs execution role; Fargate vs EC2; EKS (IRSA, VPC CNI, LB controller, Karpenter); App Runner; choose table.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators