Support for Custom Handlers (Golang) with Azure Functions Flex Consumption Tier

Guy Dillen 76 Reputation points
2025-11-08T12:47:57.05+00:00

I have a general question:

Does Azure Functions Flex Consumption Tier has support for Custom Handlers and in my case for Golang! In fact similar as before in the Consumption Tier.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jerald Felix 8,465 Reputation points
    2025-11-08T15:09:43.69+00:00

    Hello Guy Dillen,

    Greetings!

    Thanks for raising this query in the community. Yes, Azure Functions fully supports custom handlers written in Golang (Go), allowing you to implement serverless functions in Go without relying on the built-in runtimes—it's been GA since ~2021 and works seamlessly with runtime v4 (~4.0+), handling HTTP triggers/bindings via a lightweight HTTP server you provide. Custom handlers route events from the Functions host to your Go app (e.g., using net/http or Gin), making Go a first-class option for performance-critical workloads; no native Go runtime exists, but this achieves the same flexibility with cross-platform binaries.learn.microsoft+3

    How to Implement Go Custom Handlers

    Custom handlers are HTTP servers that listen on a Unix socket (local) or HTTP port (remote), responding to Azure's event format (e.g., JSON with method, path, body). Here's a step-by-step for a basic HTTP trigger:

    Set Up Project Structure:

    Create a folder (e.g., go-azure-function) with:

         `go.mod` (init with `go mod init handler`).
         
               `handler.go` (your HTTP server).
               
                     `host.json` (Functions config).
                     
                           `local.settings.json` (dev secrets).
                           
                              Example `go.mod`:
                              
                              ```yaml
                              text
                              module handler
    

    go 1.23 require github.com/gin-gonic/gin v1.9.1 // Optional for routing ```

                              **Implement the Go Handler** (`handler.go`):
                              
                                 Use `net/http` for basics or Gin for advanced routing. Handle `/admin/host/status` (health check) and `/api/<function-name>` routes.
                                 
                                    Example with Gin (adapt for net/http):
                                    
                                    ```go
                                    go
                                    package
                                    ```
                                    
                                          Compile: `GOOS=linux GOARCH=amd64 go build -o handler` (no .exe on Linux; use `handler.exe` for Windows).
                                          
                                          **Configure `host.json`** (Points to your binary):
                                          
                                          ```json
                                          json
                                          {
    

    "version": "2.0", "customHandler": { "description": { "defaultExecutablePath": "handler",
    ```

                                             `local.settings.json`:
                                             
                                             ```json
                                             json
                                             {
    

    "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "custom" } } ```

                                             **Create Function Definition**:
                                             
                                                Add folder `Hello` (matches route) with `function.json`:
                                                
                                                ```json
                                                json
                                                {
    

    "scriptFile": "../handler",
    ```

                                                **Local Development and Deployment**:
                                                
                                                   Install Azure Functions Core Tools (v4+): `npm i -g azure-functions-core-tools@4`.
                                                   
                                                      Run locally: `func start`—test at `http://localhost:7071/api/hello?name=World`.
                                                      
                                                         Deploy: `func azure functionapp publish <app-name> --no-build` (build Go binary first).
                                                         
                                                            In Azure portal: Create Function App > Runtime stack: "Custom Handler" > Version: ~4 > Deploy ZIP or via VS Code extension (use Advanced for Go).[learn.microsoft+2](https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-other)​
                                                            
    

    Limitations and Tips

    Runtime: v4 only (v3 deprecated); Go 1.23+ supported, but test binaries for Linux (Functions host OS).

    Bindings: Works for HTTP/Timer; advanced bindings (e.g., CosmosDB) need manual handling in Go (parse triggers from body).

    Cold Starts: Go binaries are fast (~100ms), but ensure no heavy deps; use --no-restore for deploys.

    Troubleshooting: If "No stacks found for 'custom'", use VS Code Advanced creation or set FUNCTIONS_WORKER_RUNTIME=custom in App Settings. Logs via Application Insights or az monitor log-analytics query.learn.microsoft+1

    Alternatives: For production, consider Azure Container Apps for full Go apps if Functions bindings limit you.

    This setup deploys a Go HTTP server as Functions—scalable, cost-effective (~$0.20/million executions). For your custom handler needs, start with the VS Code tutorial for a full walkthrough. I hope it will solve your issue.

    Best Regards,

    Jerald Felix


Your answer

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