Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement for marking instances unhealthy in ASG #799

Open
raisedadead opened this issue Jul 9, 2024 · 0 comments
Open

Enhancement for marking instances unhealthy in ASG #799

raisedadead opened this issue Jul 9, 2024 · 0 comments

Comments

@raisedadead
Copy link
Member

fetch_instance_id() {
  local retries=5
  for ((i = 0; i < retries; i++)); do
    INSTANCE_ID=$(curl -sS --fail "http://169.254.169.254/latest/meta-data/instance-id" || echo "")
    if [[ -n "$INSTANCE_ID" ]]; then
      return 0
    fi
    echo "Retry $((i + 1))/$retries: Failed to fetch instance ID. Retrying..."
    sleep 5
  done
  echo "Failed to fetch instance ID after $retries retries."
  return 1
}


mark_instance_unhealthy() {
  fetch_instance_id || return 1  # Ensures we only proceed if instance ID is obtained
  local region=$(curl -sS --fail "http://169.254.169.254/latest/meta-data/placement/region" || echo "us-east-1")
  aws autoscaling set-instance-health --instance-id "$INSTANCE_ID" --health-status Unhealthy --region "$region"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant