Question

Difficulty: MediumCreate and Configure Azure Functions

A developer needs to configure a local development environment for a lightweight Go application using the Azure Functions Core Tools custom handler feature and test the function locally. Which sequence of steps should the developer perform?

  1. 1Run 'func init --worker-runtime custom' in the command line.
  2. 2Run 'func new --template "HTTP trigger" --name GoHandler' to add a new function trigger.
  3. 3Compile the Go application source code into an executable file named 'handler'.
  4. 4Modify the 'host.json' file to set the 'defaultExecutablePath' property under the 'customHandler.description' section to 'handler'.
  5. 5Run 'func start' to launch the Azure Functions host locally.

Answer

The correct sequence is: Run 'func init --worker-runtime custom' in the command line, run 'func new --template "HTTP trigger" --name GoHandler' to add a new function trigger, compile the Go application source code into an executable file named 'handler', modify the 'host.json' file to set the 'defaultExecutablePath' property under the 'customHandler.description' section to 'handler', and finally run 'func start' to launch the Azure Functions host locally.
The correct sequence flows from establishing the local directory layout (init), creating the function trigger metadata (new), generating the executable from Go code (compile), mapping the host to this executable (host.json configuration), and executing the Functions runtime host (start).

Step-by-Step Solution

1
Initialize the project using 'func init --worker-runtime custom'.
Creates the project folder structure containing host.json and local.settings.json configured for a custom worker.
You must establish the Azure Functions project structure before you can add functions or configure handlers.
2
Create the function trigger using 'func new'.
Creates a function directory with a function.json defining the triggers and bindings.
A custom handler still relies on standard function.json metadata to determine which events should trigger the custom process.
3
Compile the Go source code.
Produces a standalone executable binary file (e.g., 'handler').
Go is a compiled language; the custom handler requires a compiled binary to receive requests forwarded by the host.
4
Configure the 'defaultExecutablePath' in host.json.
Points host.json to the compiled Go binary.
The Functions host reads host.json at startup to know the filename and location of the custom handler process to start.
5
Run 'func start'.
Launches the runtime and handler locally to accept requests.
Running the host requires all config and binaries to be in place, allowing you to test the HTTP execution locally.

Key Concept

Azure Functions Custom Handlers configuration and local development lifecycle
Rate this question