Advertisement
perimcomm

ECS-AutoScaling Error

Mar 22nd, 2019
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. resource "aws_appautoscaling_target" "ecs-running-service" {
  2. max_capacity = "${var.ecs_max_desired_count}"
  3. min_capacity = "${var.ecs_desired_count}"
  4. resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.ecs-service.name}"
  5. scalable_dimension = "ecs:service:DesiredCount"
  6. service_namespace = "ecs"
  7. }
  8. resource "aws_appautoscaling_policy" "ecs-decreasing-service-size" {
  9. depends_on = ["aws_appautoscaling_target.ecs-running-service"]
  10. name = "${var.ecs_policy_scaling_down}"
  11. policy_type = "StepScaling"
  12. resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.ecs-service.name}"
  13. scalable_dimension = "${aws_appautoscaling_target.ecs-running-service.scalable_dimension}"
  14. service_namespace = "${aws_appautoscaling_target.ecs-running-service.service_namespace}"
  15. step_scaling_policy_configuration {
  16. adjustment_type = "ChangeInCapacity"
  17. cooldown = 300
  18. metric_aggregation_type = "Average"
  19. step_adjustment {
  20. metric_interval_upper_bound = "0"
  21. scaling_adjustment = "-1"
  22. }
  23. }
  24. }
  25.  
  26.  
  27. resource "aws_appautoscaling_policy" "ecs-increasing-service-size" {
  28. depends_on = ["aws_appautoscaling_target.ecs-running-service"]
  29. name = "${var.telecarga_scale_out}"
  30. policy_type = "StepScaling"
  31. resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.ecs-service.name}"
  32. scalable_dimension = "ecs:service:DesiredCount"
  33. service_namespace = "ecs"
  34. step_scaling_policy_configuration {
  35. adjustment_type = "ChangeInCapacity"
  36. cooldown = 180
  37. metric_aggregation_type = "Average"
  38. step_adjustment {
  39. metric_interval_upper_bound = "0"
  40. scaling_adjustment = "2"
  41. }
  42. }
  43. }
  44.  
  45.  
  46. #CloudWatch Alarms
  47.  
  48. resource "aws_cloudwatch_metric_alarm" "ecs-cpu-high" {
  49. alarm_name = "${var.application_name}"
  50. alarm_actions = ["${aws_autoscaling_policy.autoscaling-policy-increase.arn}", "${aws_appautoscaling_policy.ecs-increasing-service-size.arn }"]
  51. evaluation_periods = "2"
  52. datapoints_to_alarm = "2"
  53. metric_name = "CPUUtilization"
  54. period = "60"
  55. statistic = "Average"
  56. comparison_operator = "GreaterThanOrEqualToThreshold"
  57. namespace = "AWS/ECS"
  58. threshold = "15"
  59. alarm_description = "Monitoring CPU ECS instances utilization"
  60. dimensions = {
  61. ClusterName = "${aws_ecs_cluster.cluster.name}"
  62. ServiceName = "${aws_ecs_service.ecs-service.name}"
  63. }
  64. }
  65.  
  66. resource "aws_cloudwatch_metric_alarm" "ecs-cpu-low" {
  67. alarm_name = "${var.application_name}-cpu-low"
  68. alarm_actions = ["${aws_appautoscaling_policy.ecs-decreasing-service-size.arn}", "${aws_autoscaling_policy.autoscaling-policy-decrease.arn}"]
  69. evaluation_periods = "2"
  70. datapoints_to_alarm = "2"
  71. metric_name = "CPUUtilization"
  72. period = "300"
  73. comparison_operator = "LessThanOrEqualToThreshold"
  74. statistic = "Average"
  75. namespace = "AWS/ECS"
  76. threshold = "5"
  77. alarm_description = "Monitoring CPU ECS instances utilization"
  78. dimensions = {
  79. ClusterName = "${aws_ecs_cluster.cluster.name}"
  80. ServiceName = "${aws_ecs_service.ecs-service.name}"
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement