Skip to content

3-tier web app on a VPC

The classic container web app: an Application Load Balancer in front of an autoscaling ECS Fargate service, backed by RDS for durable data and ElastiCache (Redis) for sessions and caching — all inside a VPC across two availability zones.

  1. Drop a VPC with two subnets (Flowright wires the VPC plumbing — IGW, route tables, NAT).
  2. Add an ALB and connect the Internet entrypoint to it.
  3. Add an ECS Fargate service; wire the ALB’s target-group socket to it. Set autoScaling, targetCpuPercent, and min/maxCapacity — these drive both the generated aws_appautoscaling_* resources and the simulator.
  4. Add an RDS instance; wire it to the service’s database socket and put it on the private subnets.
  5. Add ElastiCache (Redis) for caching/sessions and wire it to the service.
  6. Wire security groups so only the ALB reaches the service and only the service reaches the data tier.

Because scaling config lives on the node, the generated Terraform includes the scaling target and policy, and the simulator reads the same numbers — so what you watch scale is what you’ll deploy.

resource "aws_ecs_service" "web" {
name = "web"
cluster = aws_ecs_cluster.main.id
desired_count = 2
launch_type = "FARGATE"
load_balancer {
target_group_arn = aws_lb_target_group.web.arn
container_name = "web"
container_port = 8080
}
}
resource "aws_appautoscaling_target" "web" {
max_capacity = 10
min_capacity = 2
resource_id = "service/main/web"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}
  • Push traffic in the simulator and watch the service scale out, then settle.
  • Add per-environment overrides so prod gets a larger instance class than dev.