'Generating alert if AWS instances stops during scheduled period
We have used Instance Scheduler to start and stop the instances in different regions at specified time & its working great. Now we want to receive an alert if the instances stops due to an issue on AWS side or if someone manually stops those during the scheduled period.
Like say our instances run between 9am to 7pm everyday from Mon-Fri. If the instance stops for any reason during this time, we want to receive an email alert. Does AWS have service that we can use or need some other way to generate this kind of alerts?
Thanks.
Solution 1:[1]
Use EventBridge to create a rule that will be triggered whenever an EC2 instance is stopped:
{
"source": ["aws.ec2"],
"detail-type": ["EC2 Instance State-change Notification"],
"detail": {
"state": ["stopped"]
}
}
and configure the rule to trigger a custom lambda function. Write a lambda function that inspects the payload received as part of the invocation and that checks the time of the event. If your criteria is matched (so if the event happens outside of the 9am to 7pm window), have it so the lambda sends an email to you via SES.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Paolo |