Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

CI/CD: Added alarms and recovery to cloudformation-create-ec2.yml (#711)

Michał Rutka090726085788
diff --git a/.ci_cd/aws/cloudformation-create-ec2.yml b/.ci_cd/aws/cloudformation-create-ec2.yml
index 1846fcd33..307bbe535 100644
--- a/.ci_cd/aws/cloudformation-create-ec2.yml
+++ b/.ci_cd/aws/cloudformation-create-ec2.yml
@@ -634,3 +634,76 @@ Resources:
Properties:
InstanceId: !Ref EC2Instance
EIP: !Ref IPAddress
+
+# Telemetry and Alarms
+
+ EmailSubscription:
+ Type: AWS::SNS::Subscription
+ Properties:
+ Endpoint: [email protected]
+ Protocol: email
+ TopicArn: !Ref SnsTopic
+
+ SnsTopic:
+ Type: AWS::SNS::Topic
+ Properties:
+ DisplayName: !Sub ${Host}.${EC2Instance}
+
+ SystemStatusAlarm:
+ Type: AWS::CloudWatch::Alarm
+ Properties:
+ Namespace: AWS/EC2
+ MetricName: StatusCheckFailed_System
+ Statistic: Minimum
+ Period: 60
+ EvaluationPeriods: 2
+ ComparisonOperator: GreaterThanThreshold
+ Threshold: 0
+ AlarmActions:
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:recover"
+ - !Ref SnsTopic
+ OKActions:
+ - !Ref SnsTopic
+ Dimensions:
+ - Name: InstanceId
+ Value: !Ref EC2Instance
+
+ InstanceStatusAlarm:
+ Type: AWS::CloudWatch::Alarm
+ Properties:
+ Namespace: AWS/EC2
+ MetricName: StatusCheckFailed_Instance
+ Statistic: Minimum
+ Period: 60
+ EvaluationPeriods: 3
+ ComparisonOperator: GreaterThanThreshold
+ Threshold: 0
+ AlarmActions:
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:reboot"
+ - !Ref SnsTopic
+ OKActions:
+ - !Ref SnsTopic
+ Dimensions:
+ - Name: InstanceId
+ Value: !Ref EC2Instance
+
+ CPUUtilizationAlarm:
+ Type: AWS::CloudWatch::Alarm
+ Properties:
+ Namespace: AWS/EC2
+ MetricName: CPUUtilization
+ Statistic: Average
+ Period: 60
+ EvaluationPeriods: 4
+ ComparisonOperator: GreaterThanThreshold
+ Threshold: 90
+ AlarmActions:
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:reboot"
+ - !Ref SnsTopic
+ OKActions:
+ - !Ref SnsTopic
+ Dimensions:
+ - Name: InstanceId
+ Value: !Ref EC2Instance
+
+