Question

Difficulty: MediumCreate and Configure Azure Functions

You are developing a Go-based web service that needs to be hosted as an Azure Function. You plan to use a custom handler. You need to configure your local project environment for the custom handler before deploying it to Azure. Which four actions should you perform in sequence to set up the project? To answer, move the appropriate actions from the list of actions to the answer area and arrange them in the correct order.

  1. 1Initialize a local functions project by running the `func init` command with the `--worker-runtime custom` parameter.
  2. 2Write the Go application code and compile it into an executable binary file.
  3. 3Configure the `host.json` file by adding the `customHandler` configuration section and defining the path to the executable binary in the `defaultExecutablePath` property.
  4. 4Create a subdirectory for the function and add a `function.json` file to define the function's trigger and binding configurations.

Answer

Initialize the project using `func init --worker-runtime custom`, compile the Go application to an executable binary, configure the `host.json` file with the `customHandler` section pointing to the binary, and create a function folder with a `function.json` file to define triggers and bindings.
To set up an Azure Function custom handler, you first initialize the project environment with a custom worker runtime. Next, you compile your web server application code into an executable binary. You then configure the `host.json` file's `customHandler` section, specifying the path to the executable. Finally, you create a function folder and define the bindings in a `function.json` file.

Step-by-Step Solution

1
Run `func init` with custom runtime.
Creates the base configuration files like `host.json` and `local.settings.json` configured for a custom handler.
This establishes the project framework before adding custom handler code.
2
Compile Go code to an executable binary.
Generates the binary file that the Functions runtime will launch.
Custom handlers require a compiled binary or process to handle requests from the Functions host.
3
Configure the `customHandler` block in `host.json`.
Updates the Functions host configuration so it points to the executable binary.
The Functions host must know the path of the executable via `defaultExecutablePath` to launch it.
4
Create function folder with `function.json`.
Registers the function endpoints and their bindings within the Functions host.
Each endpoint must have its own directory containing a `function.json` metadata file to describe the input triggers and output bindings.

Key Concept

Azure Functions Custom Handlers configures the host to forward events to a lightweight web server executable via the host.json configuration and function.json trigger definitions.
Rate this question