问题描述
我想使用ebextensions将cloudwatch警报添加到一个弹性beantalk环境中.
I want to add a cloudwatch alarm to an elastic beanstalk environment using ebextensions.
所以我创建了一个 .ebextensions/cloudwatch-alarms.confg
文件,如下所示:
So I created a .ebextensions/cloudwatch-alarms.confg
file that looks like the following:
Resources:
ELBLatencyAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": HIGH ELB latency." ]]}
Namespace: AWS/ApplicationELB
MetricName: Latency
Dimensions:
- Name: LoadBalancer
Value : "arn:aws:elasticloadbalancing:xx-xxxxxx-1:123456789012:loadbalancer/app/awseb-AWSEB-oooooooooooo/12b68287xxxxxxxx"
Statistic: Average
Period: 300
EvaluationPeriods: 1
Threshold:
Fn::GetOptionSetting:
OptionName: ELBLatency
DefaultValue: "0.5"
ComparisonOperator: GreaterThanThreshold
我还没有弄清的一件事是如何使用函数获取负载均衡器的ARN.
One thing that I haven't figured out is how to use functions to get the ARN of the load balancer.
负载均衡器的代码 arn:aws:elasticloadbalancing:xx-xxxxxx-1:123456789012:loadbalancer/app/awseb-AWSEB-oooooooooooooo/12b68287xxxxxxxx
由弹性beantalk创建.在创建环境之前我不知道.
The arn of the load balancer, arn:aws:elasticloadbalancing:xx-xxxxxx-1:123456789012:loadbalancer/app/awseb-AWSEB-oooooooooooo/12b68287xxxxxxxx
, is created by elastic beanstalk. I don't know it before the environment got created.
我想我可能可以使用此处获得负载均衡器的信息.但是我还没有想出怎么做.
I think probably I can use the functions described here to get the arn of the load balancer. But I haven't figured how to do it.
有人知道该怎么做吗?
推荐答案
根据文档:
因此,如果您使用的是当前负载均衡器(即ALB或NLB,而不是CLB),则应该能够在负载均衡器的逻辑名称上使用 Ref
函数:
So if you're using a current-generation load balancer (ie ALB or NLB, not CLB), you should just be able to use the Ref
function on the load balancer's logical name:
Value: !Ref MyLoadBalancer
我还发现了此内建的beantalk资源名称列表,对于获取与自动生成的用于模板的体系结构相关的属性非常有用.
I have also found this list of 'built-in' beanstalk resource-names very useful for getting properties associated with pieces of the architecture that are auto-generated for use in templates.
仅供参考,资源的逻辑名称"通常是您为其分配的名称,作为模板中 Resources
属性的子代,例如
FYI the "logical name" of a resource is usually one you assign it, as a child of the Resources
property in your template, e.g.
Resources:
MyLoadBalancer:
...
MyS3Bucket:
...
此处的逻辑名称为 MyLoadBalancer
和 MyS3Bucket
.如果尚未定义它们,则使用上面链接中的列表中的名称,因此您的负载均衡器可能是 AWSEBLoadBalancer
或 AWSEBV2LoadBalancer
,具体取决于它是经典版本还是最新版本-gen负载均衡器.
The logical names here are MyLoadBalancer
and MyS3Bucket
. If you have not defined them then use the names in the list linked above, so your load balancer will probably be either AWSEBLoadBalancer
or AWSEBV2LoadBalancer
, depending on whether it's a classic or current-gen load balancer.
这篇关于如何在.ebextensions中获取负载均衡器的ARN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!