Express Gateway Service
Overview
Section titled “Overview”The Express Gateway Service
The aws_ecs_express_gateway_service Terraform resource that provisions an ECS service with managed ALB, auto scaling, and simplified configuration for HTTP/HTTPS web applications and APIs. is the core Terraform resource. It replaces the typical combination of aws_ecs_service, aws_lb, aws_lb_target_group, and aws_lb_listener with a single resource.
resource "aws_ecs_express_gateway_service" "this" { service_name = "${var.prefix}-service" cluster = aws_ecs_cluster.this.arn task_definition = aws_ecs_task_definition.this.arn infrastructure_role_arn = aws_iam_role.infrastructure.arn desired_count = 1
primary_container { container_name = "${var.prefix}-container" container_port = 8000 health_check_path = "/health" }
network_configuration { subnets = aws_subnet.public[*].id security_groups = [aws_security_group.web.id] access_type = "PUBLIC" }
scaling_target { auto_scaling_metric = "CPU" auto_scaling_target_value = 70 min_task_count = 1 max_task_count = 4 }}Primary Container
Section titled “Primary Container”Defines how the routes traffic to your application:
primary_container { container_name = "${var.prefix}-container" container_port = 8000 health_check_path = "/health"}| Parameter | Description |
|---|---|
container_name | Must match the |
container_port | Port the container listens on — ALB forwards traffic here |
health_check_path | HTTP path the ALB uses to verify the container is healthy |
Network Configuration
Section titled “Network Configuration”Determines where tasks run and how the ALB is provisioned:
network_configuration { subnets = aws_subnet.public[*].id security_groups = [aws_security_group.web.id] access_type = "PUBLIC"}| Parameter | Description |
|---|---|
subnets | Single list for both ALB and task placement — no split supported |
security_groups | Must allow ingress on |
access_type |
|
Scaling Target
Section titled “Scaling Target”Configures auto scaling so the service adjusts capacity based on load:
scaling_target { auto_scaling_metric = "CPU" auto_scaling_target_value = 70 min_task_count = 1 max_task_count = 4}| Parameter | Description |
|---|---|
auto_scaling_metric | Metric for target tracking — |
auto_scaling_target_value | Target percentage — scales out when exceeded |
min_task_count | Minimum running tasks — never scales below this |
max_task_count | Maximum running tasks — ceiling for scale-out |
Top-Level Parameters
Section titled “Top-Level Parameters”| Parameter | Description |
|---|---|
service_name | Immutable after creation — changing requires service replacement |
cluster | ARN of the ECS cluster |
task_definition | ARN of the task definition describing the container(s) |
infrastructure_role_arn | Infrastructure Role |
desired_count | Initial task count — auto scaling adjusts this between min and max |