Reboot an instance, with a Cloud Watch Alarms based on custom metric

0

My EC2 instance periodically send a custom metric with :

aws cloudwatch put-metric-data  --namespace "CICD" --dimensions InstanceID="$MY_INSTANCEID" --metric-name "CICD_IS_UP" --unit Count --value "$is_up" --region eu-west-1

So the metric, in the namespace "CICD" contains the InstanceID and a CICD_IS_UP value (0 when down, 1 when up).

I want to have an automatic action to reboot the instance when the metric is 0 (CICD down !).

So, I created a CloudWatch ALARM :

  • I select the metric in CICD namespace
  • I define metric level etc...
  • Because the metric is defined with an InstanceID dimension, I can see the value of the Id in the "InstanceID" field of the metric wizzard
  • But on the "Configure Actions" step, the "EC2 Action" panel contains "This action is only available for EC2 Per-Instance Metrics" but it is greyed : I'm unable to add an EC2 action.

How can I enable EC2 action on a custom metric ? The metric have the InstanceID dimension, but CloudWatch Alarms seems to ignore it.

Edited by: JeromeF on Nov 29, 2019 4:58 AM

Edited by: JeromeF on Nov 29, 2019 4:59 AM

JeromeF
질문됨 4년 전489회 조회
1개 답변
0

After double-double-checking on other AWS account, I found the problem : the dimension name for the instance must be spelled InstanceId, not InstanceID.

Strange behavior of the Create Alarm wizzard : it detects the instance ID even if it is spelled ID instead of Id. But the Action will not be enabled.

JeromeF
답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠