You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Networking is fundamental to running containers in production. Your tasks need to receive traffic, communicate with each other, access databases, and connect to the internet — all securely. This lesson covers ECS networking modes, load balancer integration, service discovery, and network architecture patterns.
ECS supports several network modes, each with different trade-offs:
Every task gets its own Elastic Network Interface (ENI) with a private IP address from your VPC. This is the default for Fargate and the recommended mode for EC2 as well.
VPC (10.0.0.0/16)
├── Subnet A (10.0.1.0/24)
│ ├── Task 1 — ENI → 10.0.1.15
│ └── Task 2 — ENI → 10.0.1.22
└── Subnet B (10.0.2.0/24)
├── Task 3 — ENI → 10.0.2.8
└── Task 4 — ENI → 10.0.2.31
Advantages:
Consideration: Each ENI consumes an IP address from your subnet. For large deployments, ensure your subnets have enough IP addresses.
Uses Docker's built-in bridge network. Containers share the host's IP address but use different port mappings.
Containers share the host's network namespace directly. No port mapping — the container binds directly to the host's ports.
Load balancers distribute incoming traffic across your ECS tasks, providing high availability and fault tolerance.
The ALB operates at Layer 7 (HTTP/HTTPS) and is the most common choice for ECS services.
Internet
|
v
+-------+
| ALB |
+-------+
|
+----------+----------+
| | |
Task 1 Task 2 Task 3
10.0.1.15 10.0.2.8 10.0.1.22
Key features:
/api/* to one service and /web/* to anotherapi.example.com to one service and web.example.com to anotherThe NLB operates at Layer 4 (TCP/UDP) and is designed for ultra-high performance and low latency.
When to use NLB:
| Feature | ALB | NLB |
|---|---|---|
| Layer | 7 (HTTP/HTTPS) | 4 (TCP/UDP/TLS) |
| Routing | Path, host, header, query string | Port-based |
| Performance | High | Ultra-high |
| Static IP | No (use Global Accelerator) | Yes |
| SSL termination | Yes | Yes (TLS) |
| WebSocket | Yes | Yes |
| gRPC | Yes | Yes |
An ALB forwards traffic to a target group. For ECS with awsvpc networking, the target type is ip:
aws elbv2 create-target-group \
--name my-web-tg \
--protocol HTTP \
--port 3000 \
--vpc-id vpc-0123456789abcdef0 \
--target-type ip \
--health-check-path /health \
--health-check-interval-seconds 30 \
--healthy-threshold-count 2 \
--unhealthy-threshold-count 3
The ALB performs HTTP health checks against your tasks. If a task fails the health check, the ALB stops sending traffic to it and ECS replaces it.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.