我们希望根据 SQS 大小自动缩放。
我能够点击以下链接并在自动扩展组中添加自定义自动扩展策略。
{
"CustomizedMetricSpecification": {
"Metrics": [
{
"Label": "Get the queue size (the number of messages waiting to be processed)",
"Id": "m1",
"MetricStat": {
"Metric": {
"MetricName": "ApproximateNumberOfMessagesVisible",
"Namespace": "AWS/SQS",
"Dimensions": [
{
"Name": "QueueName",
"Value": "my-queue"
}
]
},
"Stat": "Sum"
},
"ReturnData": false
},
{
"Label": "Get the group size (the number of InService instances)",
"Id": "m2",
"MetricStat": {
"Metric": {
"MetricName": "GroupInServiceInstances",
"Namespace": "AWS/AutoScaling",
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": "my-asg"
}
]
},
"Stat": "Average"
},
"ReturnData": false
},
{
"Label": "Calculate the backlog per instance",
"Id": "e1",
"Expression": "m1 / m2",
"ReturnData": true
}
]
},
"TargetValue": 100
}
执行此代码片段后,我看到两个警报,一个用于缩小规模,另一个用于缩小规模。
问题:上述步骤是否也会将指标数据发布到Cloudwatch?因为我没有看到指标数据填充,这意味着没有发生缩放。
您不需要将任何 SQS 指标发送到 CloudWatch,它们默认由 SQS 发送。您可以在 CloudWatch 中找到
ApproximateNumberOfMessagesVisible
指标,您只需向 my-queue
发送消息并稍等一下(实际上,可能需要几分钟)。