我已经创造了一个CloudFormation弹性青苗和CloudWatch的警报用下面的代码片段:
"ElasticBeanstalkEnvironment": {
"Type": "AWS::ElasticBeanstalk::Environment",
"Properties": {
"ApplicationName": "my-app",
"EnvironmentName": "my-eb",
"SolutionStackName": "64bit Amazon Linux 2018.03 v3.0.1 running Tomcat 8 Java 8",
"OptionSettings": [
{
"Namespace": "aws:elb:loadbalancer",
"OptionName": "CrossZone",
"Value": "true"
},
{
"Namespace": "aws:elb:listener:80",
"OptionName": "ListenerProtocol",
"Value": "HTTP"
},
{
"Namespace": "aws:elb:listener:80",
"OptionName": "InstancePort",
"Value": "80"
},
etc...
]
},
"CloudWatchBacken500XXAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties" : {
"AlarmActions": ["arn:aws:sns:us-east-1:12345678:mysnstopic"],
"Namespace": "AWS/ELB",
"Dimensions": [{
"Name": "LoadBalancerName",
"Value" : {
"Fn::GetAtt": [
"ElasticBeanstalkEnvironment",
"EndpointURL"
]
}
}],
"MetricName": "HTTPCode_Backend_5XX",
"Statistic": "Sum",
"Period": "60",
"EvaluationPeriods": "1",
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"Threshold": "1"
}
}
你可以看到,如果弹性魔豆的负载平衡器收到5XX错误的CloudWatch的警报配置警告。 但是我不能让这将是这个样子的负载均衡器名称属性:
awseb-e-a-AWSEBLoa-AY8LC6V30OAW
相反,FN :: GetAtt(“EndpointURL”)属性返回负载平衡器的DNSNAME这看起来是这样的:
awseb-e-a-AWSEBLoa-AY8LC6V30OAW-175133046.us-east-1.elb.amazonaws.com
这将无法正确地创建CloudWatch的警报,因为它期望得到负载平衡器名称不DNSNAME。
什么是让负载平衡器的名称的最好方法? 我不希望有创建负载平衡器外部资源,如“AWS :: ElasticLoadBalancing ::负载平衡器”,或尝试使用一些子法提取的DNSNAME字符串名称的字符串。