Score:0

AWS set ec2 instance as unhealthy if specific service is down

sk flag

I have couple of instances part of ASG, these are worker ec2 instances not exposed to the public, there is a systemctl service initialized via user-data, sometimes initializing the service fails for a reason or another.

When such case happens I need a way to set the instance is unhealthy so that the ASG replaces it.

I thought if having cronjob running inside the ec2 instance or lambda function and trigger update-health-check but I think this is anti-pattern.

The custom up/down 0/1 cloudwatch matrix and an alarm based on the value to set it as healthy could be the solution, is there is any out of the box design to solve this trivial workflow?

Tim avatar
gp flag
Tim
What kind of health check is the autoscaling group using to determine if the instance is health? One way to solve this is to make sure the health check returns unhealthy, which might mean a bit of scripting. A custom script can do any checking required, return (something like) http 400 (ok) status code if it works, otherwise return a 5xx code. It should log a message to Cloudwatch logs so you know what the problem was and can fix it.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.