Interview Prep/AWS/ECS, EKS, ECR and Lambda

The ECS service event says `service api was unable to place a task because no container instance met all of its requirements. The closest matching container-instance ... has insufficient memory available.`

IntermediateTroubleshootingECS, EKS, ECR and Lambda
Answer

Likely causes → On the EC2 launch type, no container instance has enough free CPU, memory or ports (static host ports with bridge mode clash), or placement constraints such as distinctInstance rule them out. Capacity provider scaling may be off.

Diagnose →

aws ecs describe-services --cluster prod --services api --query 'services[].events[:5]'
aws ecs list-container-instances --cluster prod
aws ecs describe-container-instances --cluster prod --container-instances <arn> \
  --query 'containerInstances[].remainingResources[?name==`MEMORY` || name==`CPU`]'

Fix →

  1. Use a capacity provider with managed scaling, so the ASG grows when tasks are pending
  2. Use awsvpc or dynamic host ports (hostPort 0) instead of fixed ports
  3. Right-size task reservations, or move to Fargate

Prevent → Use capacity providers with targetCapacity around 90%, and alarm on pending tasks.

aws All AWS questions Roadmap: EKS, ECS & serverless on AWS

More on ECS, EKS, ECR and Lambda