Skip to content

Commit 6941837

Browse files
Speed up ECS deploys: 30s drain + 10s health checks (#44)
## Summary - Reduce ALB target group `deregistration_delay` from **300s** (AWS default) to **30s** - Reduce health check `interval` from 30s to **10s** and `unhealthy_threshold` from 3 to **2** - Wire `deregistration_delay` through registry for app.yaml override (`routing.deregistration_delay`) Deploy stabilization drops from ~6 min to ~1 min (20s health check + 30s drain). ## Test plan - [ ] Merge to main - [ ] Push trigger to platform-test-app - [ ] Verify `ecs-deploy` step completes in ~1-2 min instead of ~3-6 min - [ ] Verify target group has `deregistration_delay = 30`
1 parent d4e3744 commit 6941837

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎scripts/ecs-deploy.sh‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ set -e
1010
SCRIPT_DIR=$(dirname "$0")
1111
export ECR_URI="${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${ECR_REPO}:${IMAGE_TAG}"
1212

13-
TASK_DEF_ARN=$(aws ecs describe-services \
14-
--cluster "$CLUSTER" --services "$SERVICE" \
15-
--query 'services[0].taskDefinition' --output text)
16-
17-
aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" \
13+
# Use the latest family revision (includes structural changes from Terraform)
14+
# rather than the revision currently running on the service.
15+
aws ecs describe-task-definition --task-definition "$SERVICE" \
1816
--query 'taskDefinition' > task-def.json
1917

2018
sh "$SCRIPT_DIR/update-task-def.sh" task-def.json task-def-new.json

‎scripts/registry.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"route53_zone_id": "ref:platform.route53_zone_id",
105105
"alb_dns_name": "ref:platform.alb_dns_name",
106106
"alb_zone_id": "ref:platform.alb_zone_id",
107+
"deregistration_delay": "yaml:routing.deregistration_delay|default:30",
107108
},
108109
"rename": "routing",
109110
"output_map": {

‎terraform/modules/service-routing/main.tf‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
################################################################################
44

55
resource "aws_lb_target_group" "this" {
6-
name = "${var.project}-${var.name}"
7-
port = var.port
8-
protocol = "HTTP"
9-
vpc_id = var.vpc_id
10-
target_type = "ip"
6+
name = "${var.project}-${var.name}"
7+
port = var.port
8+
protocol = "HTTP"
9+
vpc_id = var.vpc_id
10+
target_type = "ip"
11+
deregistration_delay = var.deregistration_delay
12+
load_balancing_algorithm_type = "round_robin"
1113

1214
health_check {
1315
path = var.health_check_path
1416
protocol = "HTTP"
1517
healthy_threshold = 2
16-
unhealthy_threshold = 3
18+
unhealthy_threshold = 2
1719
timeout = 5
18-
interval = 30
20+
interval = 10
1921
matcher = var.health_check_matcher
2022
}
2123

‎terraform/modules/service-routing/variables.tf‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ variable "alb_zone_id" {
6565
description = "ALB hosted zone ID for the Route53 alias target"
6666
type = string
6767
}
68+
69+
variable "deregistration_delay" {
70+
description = "Seconds to wait for in-flight requests before deregistering targets"
71+
type = number
72+
default = 30
73+
}

0 commit comments

Comments
 (0)