Create Azure Functions

You can use azure functions to create serverless solutions in EmpowerID. Developing the azure function allows you to develop, deploy a block of code and execute without server infrastructure or web server. Workflow studio has default templates to support the development of Azure Functions.

In this tutorial, you will learn how to do the following:

  • Create an Azure Function project in Workflow Studio

  • Open the project in Visual Studio

  • Add your implementation logic

  • Publish and deploy the Azure Function

Please follow the given instructions to create Azure Functions from the Workflow Studio template.

  1. Open the Workflow Studio.

  2. Right-click on the package folder you want to create the Web Job. Click on New Extension or Library → Azure Services .Net 6.0

     

  3. Open the properties window for the extension and select the ServiceType property.

    • Azure Function (Isolated)- Choose this service type to create functions that run out-of-process in Azure Functions.

    • Azure Function (InProcess)- Choose the InProcess service type to run functions as a class library in the same process as the host.

  4. Save the AzureFunction.

  5. Double click the AzureFunction in the Solution Explorer to load it into Visual Studio.

  6. Open the Appsettings.Json file and update the AzureWebJobsStorage & FUNCTIONS_WORKER_RUNTIME values.

    1. Please make sure that FUNCTIONS_WORKER_RUNTIME is dotnet-isolated for Azure Function (Isolated)

       

    2. Please make sure that FUNCTIONS_WORKER_RUNTIME is dotnet for Azure Function (InProcess)

       

  7. You can notice the default code in the Run method in the function.cs file, the default codes are different for In-Process and Isolated functions. You can modify the method to add your logic.

    1. Azure Function - In Process

      [FunctionName("AzFuncInProcessV6Function")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; string responseMessage = string.IsNullOrEmpty(name) ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." : $"Hello, {name}. This HTTP triggered function executed successfully."; return new OkObjectResult(responseMessage); }
    2. Azure Function - Isolated

      [Function("AzFuncIsolatedV6Function")] public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req) { _logger.LogInformation("C# HTTP trigger function processed a request."); var response = req.CreateResponse(HttpStatusCode.OK); response.Headers.Add("Content-Type", "text/plain; charset=utf-8"); response.WriteString("Welcome to Azure Functions!"); return response; }
  8. Click on build or follow the instructions to deploy the Web Jobs files into a package. You can find the zip of the microservice inside ..\EmpowerID\WFS\_microservices folder. Look for the zip with the name of the WebJob you created.

  9. Please follow the instructions here to .

  10. On successful deployment to azure, you can see the deployed function in the azure function app. A screenshot below shows a deployed isolated function.

     

  11. Click on the function name to navigate to the details view. Click on the ‘Gen Function Url’ to get the function endpoint.

     

  12. You can make an HTTP call to the endpoint of the AzureFunction to test.

 

 

 

 

 

 

Â