diff --git a/modules/admin/waf.tf b/modules/admin/waf.tf index d625f65..297c6a5 100644 --- a/modules/admin/waf.tf +++ b/modules/admin/waf.tf @@ -25,7 +25,8 @@ resource "aws_wafv2_ip_set" "authorised_ips" { name = "authorised-ips" scope = "REGIONAL" ip_address_version = "IPV4" - addresses = local.authorised_ips + #addresses = local.authorised_ips + addresses = ["0.0.0.0/1"] #ND-105 temp change to capture all IP addresses, hitting the service. } resource "aws_wafv2_web_acl" "admin_alb_acl" { diff --git a/modules/ecs_auto_scaling_radius/main.tf b/modules/ecs_auto_scaling_radius/main.tf index 7b0998b..881f157 100644 --- a/modules/ecs_auto_scaling_radius/main.tf +++ b/modules/ecs_auto_scaling_radius/main.tf @@ -25,6 +25,26 @@ resource "aws_appautoscaling_policy" "ecs_policy_up" { depends_on = [aws_appautoscaling_target.radius] } +// Scaling out using memory utilisation +resource "aws_appautoscaling_policy" "ecs_policy_up_memory_average" { + name = "${var.prefix} ECS Scale Up Memory Average" + service_namespace = "ecs" + policy_type = "StepScaling" + resource_id = "service/${var.cluster_name}/${var.service_name}" + scalable_dimension = "ecs:service:DesiredCount" + + step_scaling_policy_configuration { + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Average" + + step_adjustment { + metric_interval_lower_bound = 0 + scaling_adjustment = 1 + } + } + + depends_on = [aws_appautoscaling_target.radius] +} resource "aws_appautoscaling_policy" "ecs_policy_down" { name = "${var.prefix} ECS Scale Down" @@ -151,3 +171,28 @@ resource "aws_cloudwatch_metric_alarm" "packets_low" { tags = var.tags } + +resource "aws_cloudwatch_metric_alarm" "ecs_memory_average_alarm" { + alarm_name = "${var.prefix}-ecs-memory-average-alarm" + comparison_operator = "GreaterThanOrEqualToThreshold" + evaluation_periods = "1" + metric_name = "MemoryUtilization" + namespace = "AWS/ECS" + period = "60" + statistic = "Average" + threshold = "70" + + dimensions = { + ClusterName = var.cluster_name + ServiceName = var.service_name + } + + alarm_description = "This alarm tells ECS to scale up based on average high usage of Memory in the cluster " + + alarm_actions = [ + aws_appautoscaling_policy.ecs_policy_up_memory_average.arn + ] + + treat_missing_data = "breaching" + tags = var.tags +}