Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
115 lines (114 sloc) 3.68 KB
{
"Description" : "Cloudwatch configuration for ecs cluster service",
"Parameters": {
"ServiceName": {
"Description": "Service name",
"Type": "String"
},
"ClusterName": {
"Description": "Cluster name",
"Type": "String"
},
"ECSScaleUpThreshold": {
"Description": "Threshold value for ecs scale up alarm",
"Type": "Number",
"Default": 75
},
"ECSScaleDownThreshold": {
"Description": "Threshold value for ecs scale down alarm",
"Type": "Number",
"Default": 40
}
},
"Resources": {
"ECSAutoScaleUpAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmName": { "Fn::Join": [ "", [{ "Ref" : "ServiceName" }, "-ECSAutoScaleUpAlarm" ] ] },
"AlarmDescription": "CPU alarm for ECS autoscaling group when the CPU alarm is greater than 75",
"Namespace": "AWS/ECS",
"Statistic": "Maximum",
"Period": "300",
"EvaluationPeriods": "3",
"MetricName": "CPUUtilization",
"ComparisonOperator": "GreaterThanThreshold",
"Threshold": { "Ref" : "ECSScaleUpThreshold" },
"TreatMissingData": "breaching",
"AlarmActions": [ { "Ref": "ECSScaleUpPolicy" } ],
"Dimensions": [
{ "Name": "ClusterName", "Value": { "Ref" : "ClusterName" } },
{ "Name": "ServiceName", "Value": { "Ref" : "ServiceName" } }
]
}
},
"ECSAutoScaleDownAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmName": { "Fn::Join": [ "", [{ "Ref" : "ServiceName" }, "-ECSAutoScaleDownAlarm" ] ] },
"AlarmDescription": "CPU alarm for ECS autoscaling group when the CPU alarm is less than 40",
"Namespace": "AWS/ECS",
"Statistic": "Maximum",
"Period": "60",
"EvaluationPeriods": "1",
"MetricName": "CPUUtilization",
"ComparisonOperator": "LessThanThreshold",
"Threshold": { "Ref" : "ECSScaleDownThreshold" },
"TreatMissingData": "notBreaching",
"AlarmActions": [ { "Ref": "ECSScaleDownPolicy" } ],
"Dimensions": [
{ "Name": "ClusterName", "Value": { "Ref" : "ClusterName" } },
{ "Name": "ServiceName", "Value": { "Ref" : "ServiceName"} }
]
}
},
"ECSScalableTarget" : {
"Type" : "AWS::ApplicationAutoScaling::ScalableTarget",
"Properties" : {
"MaxCapacity" : 5,
"MinCapacity" : 3,
"ResourceId" : { "Fn::Join": [ "", [ "service", "/", { "Ref" : "ClusterName" }, "/", { "Ref" : "ServiceName" } ] ] },
"RoleARN": {"Fn::Join": ["", ["arn:aws:iam::", {"Ref": "AWS::AccountId"}, ":role/global-autoscale-role"]]},
"ScalableDimension" : "ecs:service:DesiredCount",
"ServiceNamespace" : "ecs"
}
},
"ECSScaleUpPolicy": {
"Type": "AWS::ApplicationAutoScaling::ScalingPolicy",
"Properties": {
"PolicyName": "ECSScaleUpPolicy",
"PolicyType": "StepScaling",
"ScalingTargetId": { "Ref" : "ECSScalableTarget" },
"StepScalingPolicyConfiguration": {
"AdjustmentType": "ChangeInCapacity",
"Cooldown": 120,
"MetricAggregationType": "Maximum",
"StepAdjustments": [
{
"MetricIntervalLowerBound": 0,
"ScalingAdjustment": 1
}
]
}
}
},
"ECSScaleDownPolicy": {
"Type": "AWS::ApplicationAutoScaling::ScalingPolicy",
"Properties": {
"PolicyName": "ECSScaleDownPolicy",
"PolicyType": "StepScaling",
"ScalingTargetId": { "Ref" : "ECSScalableTarget" },
"StepScalingPolicyConfiguration": {
"AdjustmentType": "ChangeInCapacity",
"Cooldown": 120,
"MetricAggregationType": "Maximum",
"StepAdjustments": [
{
"MetricIntervalUpperBound": 0,
"ScalingAdjustment": -1
}
]
}
}
}
}
}