This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am sschrijver on github. | |
* I am stephanschrijver (https://keybase.io/stephanschrijver) on keybase. | |
* I have a public key ASA75ijohpUWqZh4q8WF8D4oVwqmwX9VXIpRf9CYqFpmwwo | |
To claim this, I am signing this object: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
profile = var.profile_name | |
region = var.region | |
} | |
data "aws_ecs_cluster" "ecs_cluster" { | |
cluster_name = var.ecs_cluster_name | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_appautoscaling_target" "ecs_target" { | |
max_capacity = 3 | |
min_capacity = 0 | |
resource_id = "service/${data.aws_ecs_cluster.ecs_cluster.cluster_name}/${var.service_name}" | |
role_arn = data.aws_iam_role.ecs_autoscaling_role.arn | |
scalable_dimension = "ecs:service:DesiredCount" | |
service_namespace = "ecs" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_appautoscaling_policy" "scale_up_fargate" { | |
policy_type = "StepScaling" | |
name = "sqs-scaling-up-${var.service_name}" | |
resource_id = aws_appautoscaling_target.ecs_target.resource_id | |
scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension | |
service_namespace = aws_appautoscaling_target.ecs_target.service_namespace | |
step_scaling_policy_configuration { | |
adjustment_type = "ExactCapacity" | |
metric_aggregation_type = "Average" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_appautoscaling_policy" "scale_down_fargate" { | |
policy_type = "StepScaling" | |
name = "sqs-scaling-down-${var.service_name}" | |
resource_id = aws_appautoscaling_target.ecs_target.resource_id | |
scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension | |
service_namespace = aws_appautoscaling_target.ecs_target.service_namespace | |
step_scaling_policy_configuration { | |
adjustment_type = "ExactCapacity" | |
metric_aggregation_type = "Average" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_cloudwatch_metric_alarm" "sqs_scale_out" { | |
alarm_name = "SQS-ScaleOut-${var.service_name}" | |
comparison_operator = "GreaterThanOrEqualToThreshold" | |
evaluation_periods = "1" | |
metric_name = "ApproximateNumberOfMessagesVisible" | |
namespace = "AWS/SQS" | |
period = "60" | |
threshold = "1" | |
statistic = "Sum" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_cloudwatch_metric_alarm" "sqs_scale_in" { | |
alarm_name = "SQS-ScaleIn-${var.service_name}" | |
comparison_operator = "LessThanThreshold" | |
evaluation_periods = "1" | |
metric_name = "ApproximateNumberOfMessagesVisible" | |
namespace = "AWS/SQS" | |
period = "60" | |
threshold = "1" | |
statistic = "Sum" | |
alarm_description = "SQS-ScaleIn-${var.service_name}" |