An instance is scheduled to be retired when AWS detects irreparable failure of the underlying hardware hosting the instance. When an instance reaches its scheduled retirement date, it is stopped or terminated by AWS.Under such conditions you might want to be notified in advance for preparing to stop/start the ec2 instance to move to a different underlying hardware or take necessary backups (if not using EBS) .
Good news is AWS Personal Health dashboard notifies you of all such events well in advance and you just need to create Cloudwatch event rules to trigger based on the specific event (AWS Health Service) and then get notified using your SNS topic (SMS/Mail or Slack notification).
Using the below mentioned solution you can automate this and just need to specify the ARN of your SNS topic as an input to Cloudformation.
AWSTemplateFormatVersion: 2010-09-09
Description: >-
Template to automatically trigger your SNS topic specified in parameters to notify you for your EC2 instances scheduled change notifications.
Parameters:
MySNSTopic:
Type: String
Description: Enter the ARN of your SNS topic.
Resources:
EC2ScheduledEventRule:
Type: AWS::Events::Rule
Properties:
Description: "EventRule"
EventPattern:
source:
- "aws.health"
detail-type:
- "AWS Health Event"
detail:
service:
- "EC2"
eventTypeCategory:
- "scheduledChange"
State: "ENABLED"
Targets:
-
Arn:
Ref: "MySNSTopic"
Id: "SNSTopic"
EventTopicPolicy:
Type: 'AWS::SNS::TopicPolicy'
Properties:
PolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: events.amazonaws.com
Action: 'sns:Publish'
Resource: '*'
Topics:
- !Ref MySNSTopic
You can download the Cloudformation template from this location
Comments