简体   繁体   English

如何使用aws-sdk为扩展组中的扩展策略分配警报

[英]How do I assign alarms to scaling policies in scaling group using aws-sdk

I'm using a ruby script to help facilitate managing AutoScaling on AWS EC2. 我正在使用ruby脚本来帮助管理AWS EC2上的AutoScaling。 I've managed to create AMI s, create LaunchConfigurations , create ScalingGroups , and associating one another. 我成功创建了AMI ,创建了LaunchConfigurations ,创建了ScalingGroups ,并相互关联。

I'm trying to clone a scaling group, copying its launch configurations, load balancers, etc. and its scaling policies. 我正在尝试克隆扩展组,复制其启动配置,负载平衡器等及其扩展策略。

To copy its scaling policy I have this code: 要复制其扩展策略,我有以下代码:

orig_scaling_group.scaling_policies.each do |policy|
  props = Hash[%i(adjustment_type scaling_adjustment cooldown min_adjustment_step alarms).map { |s| [s, policy.send(s)] }.reject { |k, v| v.nil? }]
  clone_scaling_group.scaling_policies[policy.name].put(props)
end

(scaling_groups are instances of AWS::AutoScaling::Group ) (scaling_groups是AWS::AutoScaling::Group实例)

This goes over the original's scaling policies, and extracts the data from it, and sets it as a new policy in the clone scaling group. 这将覆盖原始的扩展策略,并从中提取数据,并将其设置为克隆扩展组中的新策略。

This works fine, except that it does not copy the alarms to the new policy. 这样可以正常工作,除了它不会将警报复制到新策略。 I could not find anyway in which I can programmatically assign an alarm to a scaling policy. 无论如何,我无法找到我可以通过编程方式为扩展策略分配警报。

How can I do it? 我该怎么做?

I could not find anyway in which I can programmatically assign an alarm to a scaling policy. 无论如何,我无法找到我可以通过编程方式为扩展策略分配警报。

I will be restricting my response to above statement. 我将限制我对上述声明的回应。

In AWS Core Ruby SDK , under put_metric_alarm-instance_method API, you can use alarm_actions method. AWS Core Ruby SDK中 ,在put_metric_alarm-instance_method API下,您可以使用alarm_actions方法。 From above referred documentation: 从上面提到的文件:

在此输入图像描述

Please note that, above information is relevant to AWS CORE SDK Ruby and not the older AWS ruby SDK . 请注意,以上信息与AWS CORE SDK Ruby相关,而不是旧的AWS ruby​​ SDK

Also for AWS-CLI, the similar settings can be found with put-metric-alarm for --alarm-actions option. 同样对于AWS-CLI,可以使用put-metric-alarm选择--alarm-actions选项找到类似的设置。

Not sure whether this what you are looking for, but here I can certainly see a programmatic way of assigning an alarm to an Autoscaling policy. 不确定这是否是您正在寻找的,但在这里我当然可以看到一种为Autoscaling策略分配警报的编程方式。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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