Deploy multiple azure functions binaries using single repo code in GoLang

raviteja aketi 45 Reputation points
2024-02-26T08:43:57.0233333+00:00

The below configuration points to a single executable binary("defaultExecutablePath": "custom_handler") and using which it routes to a specfic end point based on url request.

But we want to isolate and generate unique functions using its binaries and dependencies. This way we can speed up the functions loading into the memory and execute very fast where as this fat binary takes more memory.

  • We tried to deploy each function separately but its overriding the previously deployed functions even though function names are different.
  • Deploying below structured project is creating multiple functions but all are sharing the same binary code which has its own disadvantage's when it comes to loading into the memory and speed of execution.

**Is there a way to isolate all these functions and execute its own binaries ? **

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "functions": [ "FunctionOne", "FunctionTwo", "FunctionThree", "FunctionFour"],
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  },
  "customHandler": {
    "description": {
      "defaultExecutablePath": "custom_handler",
      "workingDirectory": "",
      "arguments": []
    },
    "enableForwardingHttpRequest": true
  }
}


enter image description here

func CustomHandler(w http.ResponseWriter, req *http.Request) {

fmt.Println("CustomHandler Called")
switch req.URL.Path {
case "/api/FunctionOne":
	FunctionOne.Call(w, req)
case "/api/FunctionTwo":
	FunctionTwo.Call(w, req)
case "/api/FunctionThree":
	FunctionThree.Call(w, req)
case "/api/FunctionFour":
	FunctionFour.Call(w, req)
default:
	http.NotFound(w, req)
}


func main() {

listenAddr := ":8080"
if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok {
	listenAddr = ":" + val
}
http.HandleFunc("/", CustomHandler)
log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr)
log.Fatal(http.ListenAndServe(listenAddr, nil))
}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,900 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,141 Reputation points
    2024-03-05T13:31:15.3833333+00:00

    @raviteja aketi Thanks for reaching out. I have reached out to my team to confirm whether this is possible or not. AFAIK it may not be possible, but I am waiting for the team to get confirmation.

    Few suggestions that I could think of on top of my mind.

    1. Create a separate project for each function with its own binary and dependencies.
    2. Deploy each function separately using the Azure Functions Core Tools or Azure Portal.
    3. Ensure that each function has a unique name and endpoint.
    4. Verify that each function is working correctly and independently.

    Update 3/6:

    I have got confirmation from my team that this isn’t supported at the moment and would require a change to the Custom Handlers logic to support multiple binaries. You can create the feature request/bug here so the team can review it further.

    Let me know if you have any queries or concerns.

    Please 'Accept Answer' if it helped so that it can help others in the community looking for help on similar topics.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.