Get EC2 Instance Retirement Alerts in Slack!

HasanB
1 min readApr 18, 2022

Recently AWS has begun deprecating and upgrading their underlying hardware which means instances get shutdown (instance-stop event) and re-started which moves the instance to new hardware

If your long-lived instances running critical workloads such as SQL have not been set up with ASGs, then prepare for service disruption!

AWS does send out emails well in advance, but hey, emails (just like your JIRA backlog)have a high probability to go unattended

Luckily there is a workaround to get these important events directly in Slack. The below template does the following:

  • Creates an SNS Topic and Email subscription
  • Creates an EventBridge rule to forward EC2 Health events to the SNS subscription
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.
Resources:
SNSTopic:
Type: 'AWS::SNS::Topic'
Properties:
TopicName: EC2-Instance-Retirement-Alerts
DisplayName: EC2-Instance-Retirement-Alerts
Subscription:
- Endpoint: "channel_email@slack.com"
Protocol: "email"
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: "SNSTopic"
Id: "SNSTopic"
EventTopicPolicy:
Type: 'AWS::SNS::TopicPolicy'
Properties:
PolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: events.amazonaws.com
Action: 'sns:Publish'
Resource: '*'
Topics:
- !Ref SNSTopic

Refer to the link below to integrate an email address with your Slack channel and you’re all set!

--

--