An EC2 system status metric records AWS checks of the underlying host system supporting an instance. EC2 publishes StatusCheckFailed_System every minute; a failed check adds a datapoint with value 1. section 13.1
Use this metric with a CloudWatch alarm to detect host failure and invoke EC2 recovery. The alarm evaluates a threshold over time before changing to ALARM and triggering its action. section 13.1
Listing 13.2 Creating a CloudWatch alarm to recover a failed EC2 instance
RecoveryAlarm: #1
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'Recover EC2 instance when underlying hardware fails.'
Namespace: 'AWS/EC2' #2
MetricName: 'StatusCheckFailed_System' #3
Statistic: Maximum #4
Period: 60 #5
EvaluationPeriods: 5 #6
ComparisonOperator: GreaterThanThreshold #7
Threshold: 0 #8
AlarmActions: #9
- !Sub 'arn:aws:automate:${AWS::Region}:ec2:recover'
Dimensions:
- Name: InstanceId #10
Value: !Ref Instance
This CloudFormation listing configures the AWS/EC2 namespace, StatusCheckFailed_System metric, five evaluation periods, and the EC2 recovery action. section 13.1
