简体   繁体   中英

Configure the LoadBalancer in AWS CloudWatch Alarm

I have a web application on AWS and I am trying to configure my autoscaling based on the requests.

My AppLoadBalancer resource is as below:

"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"
}

I am trying to configure a CloudWatch Alarm like this:

"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"
}

However, my stack continues to fail and I don't know what is wrong here. Here is the error which I am getting.

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].

Can somebody suggest?

The property mentioned requires a string. You have it defined as a list:

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

The [] brackets defines a list in JSON. Remove the outside brackets in the Value value, and use only the Fn::GetAt portion. That call will return a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM