Skip to content

Instantly share code, notes, and snippets.

@andreaswittig
Created December 13, 2022 10:46
Show Gist options
  • Save andreaswittig/ed7f8e187e6fe1bf41ad6e059d2d402c to your computer and use it in GitHub Desktop.
Save andreaswittig/ed7f8e187e6fe1bf41ad6e059d2d402c to your computer and use it in GitHub Desktop.
Auto Scaling: Target Tracking with Metric Math
aws autoscaling put-scaling-policy \
--auto-scaling-group-name ASG_NAME \
--policy-name target-tracking \
--policy-type TargetTrackingScaling \
--target-tracking-configuration file://target-tracking-configuration.json \
--estimated-instance-warmup 300
{
"CustomizedMetricSpecification": {
"Metrics": [
{
"Id": "messages",
"MetricStat": {
"Metric": {
"Namespace": "AWS/SQS",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Dimensions": [
{
"Name": "QueueName",
"Value": "QUEUE_NAME"
}
]
},
"Stat": "Maximum",
"Unit": "Count"
},
"Label": "Enqueued Messages",
"ReturnData": false
},
{
"Id": "instances",
"MetricStat": {
"Metric": {
"Namespace": "AWS/AutoScaling",
"MetricName": "GroupTotalInstances",
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": "ASG_NAME"
}
]
},
"Stat": "Maximum",
"Unit": "Count"
},
"Label": "Instances",
"ReturnData": false
},
{
"Id": "e1",
"Expression": "FILL(instances, 1)",
"Label": "E1",
"ReturnData": false
},
{
"Id": "e2",
"Expression": "messages/IF(e1>0, e1, 1)",
"Label": "E2",
"ReturnData": true
}
]
},
"TargetValue": 0.0001,
"DisableScaleIn": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment