Sets up autoscaling for an ECS service to modify the desired count of instances according to a schedule.

Terraform Template

resource "aws_appautoscaling_scheduled_action" "ecs" {
  name = "ecs"
  resource_id = aws_appautoscaling_target.ecs.resource_id
  scalable_dimension = aws_appautoscaling_target.ecs.scalable_dimension

  scalable_target_action {
    max_capacity = 10
    min_capacity = 1
  }
  schedule = "at(2006-01-02T15:04:05)"
  service_namespace = aws_appautoscaling_target.ecs.service_namespace
}

resource "aws_appautoscaling_target" "ecs" {
  max_capacity = 4
  min_capacity = 1
  resource_id = "service/clusterName/serviceName"
  scalable_dimension = "ecs:service:DesiredCount"
  service_namespace = "ecs"
}