I have a python AWS lambda that hits a REST endpoint, if the service/endpoint is down or unreachable I want to send a notification to a teams/slack channel.
I don't want to keep sending this notification for every message while the service is down. I would like to send one message the first time it is down and then send another when it is back up.
I was thinking of having an environment variable SERVICE_UP = true. If we get an error saying service is down we notify the channel and set SERVICE_UP = false, when it changes again we send a notification saying service back up and set SERVICE_UP = true.
Pseudo code for what I am trying to achieve or else open to other suggestions, not sure i DynamoDB table might be overkill for what i am trying to achieve?
if (SERVICE_UP == true):
if (failed_call):
send_notification()
SERVICE_UP = false;
if (SERVICE_UP == false):
if (successful_call):
send_notification()
SERVICE_UP = true;