AWS CLI命令以告警附加数量筛选获取EC2实例列表:

huangapple go评论67阅读模式
英文:

AWS CLI command to get list of ec2 instances filtered according to no. of alarms attached

问题

我必须删除附加到EC2实例的一些冗余警报。为此,我需要筛选那些附加了超过2个警报的EC2实例。但我没有找到AWS提供的任何筛选实例的筛选器,以基于附加的警报来筛选它们。
此外,描述警报命令在这里没有帮助,因为每个实例都附加了唯一的警报。

英文:

I have to delete the some redundant alarms attached to the EC2 instances. For that I need to filter those EC2 instances which have more than 2 alarms attached. But I am not finding any filter provided by AWS through which I can filter the instances based on the attached alarms.
Also, describing alarms command would not help here as to every instance a unique alarm is attached.

答案1

得分: 1

这将提供一个包含在您帐户中定义的CW警报维度中的所有EC2实例的列表(相当于附加的不准确术语):

aws cloudwatch describe-alarms --query 'MetricAlarms[*].Dimensions[?(Name==`InstanceId`)].Value' --output text | sort

sort将为您提供排序后的列表,因此任何重复的InstanceId表示它有多于1个警报。

英文:

This will give a list with all ec2 instances defined in CW alarms dimensions in your account (equivalent to inaccurate term of attached):

aws cloudwatch describe-alarms --query 'MetricAlarms[*].Dimensions[?(Name==`InstanceId`)].Value' --output text | sort

The sort will give you the list ordered, so any repeated instanceId, that means it has more than 1 alarm.

huangapple
  • 本文由 发表于 2023年6月5日 17:11:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定