Amazon Elastic Container Service (ECS) (ECS)
Runs containerized microservices, REST APIs, and background job queues with zero server management using AWS Fargate, integrating with ALBs, Service Discovery, and VPC networking.
AWS Container Placement
SUBNET
Summary
Fully managed container orchestration service running Docker containers on serverless AWS Fargate or managed EC2 fleets.
When to Use (SAA-C03)
Use for microservices, Dockerized APIs, and batch containers without managing EC2 worker nodes.
Allowed Ingress Connections & Ports
| Source Service | Protocol | Port | Architectural Rationale |
|---|---|---|---|
| ALB | HTTP / HTTPS | 80, 443, 8080, 3000 | Application Load Balancer Layer 7 routing and SSL termination to container target port |
| NLB | TCP | Any TCP Port (e.g. 8080, 50051 gRPC) | Network Load Balancer high-performance Layer 4 and gRPC streaming traffic |
| APIGW | HTTP | 80, 8080 | API Gateway HTTP/REST API integration via VPC Link private integration |
| SERVICE-DISCOVERY | TCP / UDP | Any application port | Internal microservice-to-microservice communication via AWS Cloud Map Private DNS |
Allowed Egress Targets & Ports
| Target Service | Protocol | Port | Data Flow Rationale |
|---|---|---|---|
| RDS | TCP | 3306 (MySQL), 5432 (PostgreSQL) | Database read/write connection pool from containerized API handlers |
| ELASTICACHE | TCP | 6379 (Redis) | Distributed in-memory caching and session store access |
| DYNAMODB | HTTPS | 443 | Low-latency document queries and fast key-value lookups via DynamoDB Gateway Endpoint |
| ECR | HTTPS | 443 | Pulling Docker image layers from Amazon ECR private repository via VPC interface endpoints (ecr.api / ecr.dkr) |
| SECRETSMANAGER | HTTPS | 443 | Injecting database credentials and API secrets into container environment variables at task launch |
| NAT | TCP | 80, 443 | Outbound internet egress for third-party SaaS APIs, Stripe, Twilio, and external dependencies |
Key Configuration Parameters & AWS Best Practices
| Parameter | Format / Example | Purpose & Rationale |
|---|---|---|
| Launch Type (launchType) (Required) | FARGATE | Specifies the compute infrastructure provider. FARGATE provides serverless container execution where AWS manages hypervisors; EC2 uses customer-managed instances. Why: Determines operational overhead, underlying security isolation model, and pricing structure. |
| Task CPU Units (taskCpu) (Required) | 1024 (1 vCPU) | The number of CPU units reserved for the Fargate container task (1024 units = 1 vCPU). Why: AWS Fargate requires strict CPU/Memory ratio pairings to allocate virtual hardware slots. |
| Task Memory (taskMemory) (Required) | 2048 (2 GiB RAM) | The hard limit of memory allocated to the container task in MiB. Why: Containers exceeding this memory threshold trigger Linux OOM-killer termination. |
| Container Port (containerPort) (Required) | 8080 | The listening port exposed inside the Docker container image (EXPOSE in Dockerfile). Why: In awsvpc networking mode, the task ENI maps traffic directly to this container port without host port translation. |
| Target Group ARN (targetGroupArn) (Required) | arn:aws:elasticloadbalancing:...:targetgroup/ecs-api-tg/... | The Application Load Balancer Target Group configured with target type "ip" to route traffic directly to the task private IP. Why: Enables ALB to discover dynamic task IP addresses as tasks scale up and down. |
| Task Security Groups (securityGroupIds) (Required) | [sg-ecs-tasks] | Security groups attached directly to the task Elastic Network Interface (awsvpc networking). Why: Mandatory firewall boundary: allows inbound traffic strictly from the ALB security group on containerPort. |
| Container Image URI (ecsImage) | 123456789012.dkr.ecr.us-east-1.amazonaws.com/payment-service:v2.1 | Docker image repository address in Amazon ECR or public registry. Why: ECS task execution agent pulls this container image layer bundle on task launch. |
| Desired Task Count (ecsDesiredCount) | 2 | The continuous number of healthy running task instances the ECS service maintains. Why: ECS service scheduler automatically replaces stopped or unhealthy tasks to preserve this target count. |
| Task Execution Role (ecsTaskExecutionRoleArn) | arn:aws:iam::123456789012:role/ecsTaskExecutionRole | Grants the ECS container agent permission to pull images from Amazon ECR and send logs to CloudWatch. Why: Without this role, tasks in private subnets cannot authenticate with ECR to download image layers. |
| Task Role (ecsTaskRoleArn) | arn:aws:iam::123456789012:role/PaymentAppTaskRole | Grants the application code inside the container access to AWS APIs (DynamoDB, S3, SQS, KMS). Why: Enforces least privilege STS credential dispensing to application processes without hardcoded credentials. |
| Cluster Name (ecsClusterName) | production-microservices | Logical grouping of services and tasks. Why: Organizes application environments (e.g. prod-cluster, staging-cluster) for unified metrics and IAM boundaries. |
Practice Labs Using Amazon Elastic Container Service (ECS)
Enterprise Cloud Security: GitHub Actions Keyless OIDC CI/CD to Private VPC
Replace static IAM credentials with GitHub OIDC Identity Provider and IAM Role with AssumeRoleWithWebIdentity …
BUILD-10Build: Enterprise Zero-Trust PrivateLink Service Connection
Build a two-VPC architecture with an Interface VPC Endpoint in the Consumer VPC and a Network Load Balancer in…
Frequently Asked Questions
Where does Amazon Elastic Container Service (ECS) live inside an AWS VPC architecture?
Valid container placement: SUBNET. Runs containerized microservices, REST APIs, and background job queues with zero server management using AWS Fargate, integrating with ALBs, Service Discovery, and VPC networking.
When should I use Amazon Elastic Container Service (ECS) on the AWS SAA-C03 exam?
Use for microservices, Dockerized APIs, and batch containers without managing EC2 worker nodes.
Can I simulate Amazon Elastic Container Service (ECS) packet routing without an AWS account?
Yes. CloudTracer simulates Amazon Elastic Container Service (ECS) along with 53 AWS services directly in your browser and exports production Terraform HCL.