Reputation: 1702
I have the following command which does create the alarm. The only thing it does not set is to terminate the EC2 instance when the instance is in the alarm state.
I believe I do not have the following stated correctly:
--actions-enabled --alarm-actions ec2:terminate
Here is my full CLI command :
aws cloudwatch put-metric-alarm --actions-enabled --alarm-actions ec2:terminate --alarm-name "High-CPU" --alarm-description "CPU has exceeded 70" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Maximum --period 60 --threshold 70 --comparison-operator GreaterThanThreshold --dimensions Name=InstanceId,Value=$INSTANCE_ID --evaluation-periods 2 --unit Percent --alarm-actions arn:aws:sns:us-east-2:499000881936:Alarm-test
Thanks for any input!
Upvotes: 0
Views: 1055
Reputation: 12099
--actions-enabled
is the default, so you don't need it.arn:aws:automate:REGION:ec2:terminate
, like arn:aws:automate:us-east-2:ec2:terminate
--alarm-actions
takes a list of values, so you need one parameter with two values.Putting it all together:
aws cloudwatch put-metric-alarm \
--alarm-name "High-CPU" \
--alarm-description "CPU has exceeded 70" \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--statistic Maximum \
--period 60 \
--threshold 70 \
--comparison-operator GreaterThanThreshold \
--dimensions Name=InstanceId,Value=$INSTANCE_ID \
--evaluation-periods 2 \
--unit Percent \
--alarm-actions arn:aws:sns:us-east-2:499000881936:Alarm-test arn:aws:automate:us-east-2:ec2:terminate
Upvotes: 1