在AWS CloudWatch Alarm中配置LoadBalancer

时间:2017-12-28 16:51:36

标签: amazon-web-services amazon-ec2 amazon-cloudformation amazon-cloudwatch

我在AWS上有一个Web应用程序,我正在尝试根据请求配置自动缩放。

我的AppLoadBalancer资源如下:

"AppLoadBalancer": {
    "Properties": {
        "LoadBalancerAttributes": [
            {
                "Key": "idle_timeout.timeout_seconds",
                "Value": "60"
            }
        ],
        "Name": "sample-app-v1",
        "Scheme": "internet-facing",
        "SecurityGroups": [
            "sg-1abcd234"
        ],
        "Subnets": {
            "Fn::FindInMap": [
                "LoadBalancerSubnets",
                {
                    "Ref": "AWS::Region"
                },
                "Subnets"
            ]
        },
        "Tags": [
            {
                "Key": "Name",
                "Value": "sample-app-v1"
            },
            {
                "Key": "StackName",
                "Value": "sample-app"
            },
            {
                "Key": "StackVersion",
                "Value": "v1"
            }
        ]
    },
    "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer"
}

我正在尝试像这样配置CloudWatch警报:

"RequestCountTooHighAlarm": {
    "Properties": {
        "AlarmActions": [
            {
                "Ref": "ScaleUp"
            }
        ],
        "AlarmDescription": "Scale-up if request count >= 8000 for last 5 minute",
        "ComparisonOperator": "GreaterThanOrEqualToThreshold",
        "Dimensions": [
            {
                "Name": "LoadBalancer",
                "Value": [
                    {
                        "Fn::GetAtt": [
                            "AppLoadBalancer",
                            "LoadBalancerFullName"
                        ]
                    }
                ]
            }
        ],
        "EvaluationPeriods": 1,
        "MetricName": "RequestCount",
        "Namespace": "AWS/ApplicationELB",
        "OKActions": [
            {
                "Ref": "ScaleDown"
            }
        ],
        "Period": 300,
        "Statistic": "SampleCount",
        "Threshold": 8000
    },
    "Type": "AWS::CloudWatch::Alarm"
}

然而,我的筹码继续失败,我不知道这里有什么问题。这是我得到的错误。

ERROR: RequestCountTooHighAlarm CREATE_FAILED: Value of property Value must be of type String
ERROR: sample-app-v1 CREATE_FAILED: The following resource(s) failed to create: [RequestCountTooHighAlarm].

有人可以建议吗?

1 个答案:

答案 0 :(得分:1)

提到的属性需要一个字符串。您将其定义为列表:

        "Value": [
            {
                "Fn::GetAtt": [
                    "AppLoadBalancer",
                    "LoadBalancerFullName"
                ]
            } ]

[]括号在JSON中定义一个列表。删除Value值中的外部括号,并仅使用Fn::GetAt部分。该调用将返回一个字符串。