Skip to content

Commit

Permalink
Automatically scale Meadow tasks based on set schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Dec 17, 2024
1 parent 3883333 commit ae9bcb7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions infrastructure/deploy/ecs_services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,44 @@ resource "aws_ecs_service" "meadow_all" {

tags = var.tags
}

resource "aws_appautoscaling_target" "ecs_target" {
count = var.environment == "p" ? 1 : 0
max_capacity = 2
min_capacity = 1
resource_id = "service/${ aws_ecs_cluster.meadow.name}/${aws_ecs_service.meadow.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}

# Scheduled action to scale UP at 7:15 AM Central
resource "aws_appautoscaling_scheduled_action" "scale_up" {
count = var.environment == "p" ? 1 : 0
name = "scale-up-to-2-tasks"
service_namespace = aws_appautoscaling_target.ecs_target.service_namespace
resource_id = aws_appautoscaling_target.ecs_target.resource_id
scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension

schedule = "cron(15 13 ? * MON-FRI *)" # 7:15 AM Central in UTC (13:15 UTC)

scalable_target_action {
min_capacity = 2
max_capacity = 2
}
}

# Scheduled action to scale DOWN at 6:00 PM Central
resource "aws_appautoscaling_scheduled_action" "scale_down" {
count = var.environment == "p" ? 1 : 0
name = "scale-down-to-1-task"
service_namespace = aws_appautoscaling_target.ecs_target.service_namespace
resource_id = aws_appautoscaling_target.ecs_target.resource_id
scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension

schedule = "cron(0 0 ? * MON-FRI *)" # 6:00 PM Central in UTC (00:00 UTC next day)

scalable_target_action {
min_capacity = 1
max_capacity = 1
}
}

0 comments on commit ae9bcb7

Please sign in to comment.