skip to Main Content

I am trying to configure an Azure function app health check, to check the availability of a function app.

So, I have created a separate endpoint for it. It seems to be working as seen in the metrics graph below.
But the health check status is stuck at Health Check:0.00% (Healthy 0 / Degraded 1).

Do you have any idea on how to make health check to work?

My code:

import base64
import json
import logging
import os
import azure.functions as func
import requests

def main(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("", status_code=200)

Metrics graph:
enter image description here

2

Answers


  1. I think the only problem is the auth_level. The default value is function, which means A function-specific API key is required. The health check request doesn’t insert any keys, so requests to the endpoint will return 401 (Unauthorized).

    Depending on which version you use, the solution is the same, but applied at different points:

    V1

    Set the authLevel to anonymous, something like the example below:

    {
      "scriptFile": "__init__.py",
      "bindings": [
        {
          "name": "health",
          "type": "httpTrigger",
          "authLevel": "anonymous",
          "direction": "in"
        }
      ]
    }
    

    V2

    For those who are using the recent version, try to set the auth_level to ANONYMOUS like the example below:

    @app.function_name(name="HealthCheck")
    @app.route(route="health", auth_level=func.AuthLevel.ANONYMOUS)
    def health(req: func.HttpRequest) -> func.HttpResponse:
        return func.HttpResponse("", status_code=200)
    
    Login or Signup to reply.
  2. Another simple approach worth mention is to just point the health check path to the root of the application. By default it’ll return a homepage and 200 http code, which is exactly what you need.

    If your health check doesn’t require anything fancy (checking other services, etc), that change will save you some functions calls.

    Default homepage Azure Function Python

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search