Skip to content

Commit

Permalink
Reconfigured scaling down configuration (#292)
Browse files Browse the repository at this point in the history
Increased min capacity on production ecs clusters from 2 to 3.
Changed scaling config, to scale down when traffic hits an average of
20% cpu capacity.
  • Loading branch information
jamesgreen-moj authored Oct 10, 2023
1 parent dfd6130 commit 53e04b3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/dns/ecs_auto_scaling.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "aws_appautoscaling_target" "auth_ecs_target" {
service_namespace = "ecs"
resource_id = "service/${aws_ecs_cluster.server_cluster.name}/${aws_ecs_service.service.name}"
max_capacity = 12
min_capacity = 2
min_capacity = terraform.workspace == "production" ? 3 : 2
scalable_dimension = "ecs:service:DesiredCount"
}

Expand Down Expand Up @@ -48,7 +48,7 @@ resource "aws_appautoscaling_policy" "ecs_policy_up_max" {
}

resource "aws_appautoscaling_policy" "ecs_policy_down" {
name = "ECS Scale Down"
name = "ECS Scale Down Average"
service_namespace = "ecs"
resource_id = "service/${aws_ecs_cluster.server_cluster.name}/${aws_ecs_service.service.name}"
policy_type = "StepScaling"
Expand All @@ -57,6 +57,7 @@ resource "aws_appautoscaling_policy" "ecs_policy_down" {
step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
metric_aggregation_type = "Average"
cooldown = 300

step_adjustment {
metric_interval_upper_bound = 0
Expand Down Expand Up @@ -116,14 +117,14 @@ resource "aws_cloudwatch_metric_alarm" "ecs_cpu_maximum_alarm_high" {
}

resource "aws_cloudwatch_metric_alarm" "ecs_cpu_alarm_low" {
alarm_name = "${var.prefix}-ecs-cpu-alarm-low"
alarm_name = "${var.prefix}-ecs-cpu-alarm-low-average"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/ECS"
period = "60"
statistic = "Average"
threshold = "1"
threshold = "20"

dimensions = {
ClusterName = aws_ecs_cluster.server_cluster.name
Expand Down

0 comments on commit 53e04b3

Please sign in to comment.