Skip to content

VinnyBonner/LocalAzureFunctionsHostTutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Configuring Azure Function Host Locally

Based on the documentation here: Contributor Onboarding · Azure/azure-functions-host Wiki

Requirements

Visual Studio 2022 Download

Getting the Functions Host Running Locally

Download a copy of the Dev branch or whichever branch you want to test locally and extract the contents to a safe location. Azure/azure-functions-host: The host/runtime that powers Azure Functions (github.com)

Open up the WebJob.Script.sln with Visual Studios 2022

Set the WebJobs.Script.WebHost to the startup project

  1. Right click the solution in the solution explorer
  2. Click on Properties
  3. Select "Single startup project"
  4. select WebJobs.Script.WebHost

image

With the Properties opened up…

  1. Select Configuration under the Configuration Properties
  2. Set every project EXCEPT the WebJobs.Script.WebHost Configuration to "WebJobs.Script.WebHost.Core"

image

Now we need to add some Environment Variables.

  1. Click Debug from the top menu and select WebJobs.Script.WebHost Debug Properties

image

Now Select WebJosbs.Script.WebHost as the launching program

  1. Add in 2 variables, Note that they may already be there.
ASPNETCORE_ENVIRONMENT=Development
AZURE_FUNCTIONS_ENVIRONMENT=Development

image

At this point, we want to verify that host will come up locally for us.

Ensure that WebJobs.Script.WebHost shows up in the top menu like below, and click on the debug button. image

It may take a minute to come up. You can view the Console window that opens up, which will contain some logging info during the startup.

After it is running it should automatically open a browser window which will show that your functions x.0 app is up and running.

image

Setting Up DotNet Functions

To get the Locally running function host to identify and trigger a locally stored and built function is pretty straight-forward.

First we just open Visual Studios 2022 and create a simple HttpTrigger (I will mention other trigger types later).

Note: That when creating an HttpTrigger to select the Authorization Level as Anonymous. This is because when running the function host locally, it does not create the function keys used to trigger the function.

Once you are ready to publish the function, right click on the function in the solution explorer and click publish.

image

Rather then selecting the usual Azure, we will select Folder and click next.

image

On the Publish page, select the folder path of the published content. Remember that it is relative to the project path.

Note: You will need the full path for the final section.

image

Once you are on this scree, you can click Publish.

image

After it has successfully published you can click on the Target location link to open the location in a file explorer window.

Select the Url bar and highlight the full path and copy it to the clipboard

image

Configuring and trigger the local function with the locally running functions host

We now need to add the full path to the locally published function to the functions host.

Open back up the Function Host sln in Visual Studios 2022, if it isn't already still open.

Once it is open, select Debug from the top menu bar and select WebJobs.Script.WebHost Debug Properties

image

Now select the WebJobs.Script.WebHost and we are going to add a new Environment variable to the list.

Add the AzureWebJobsScriptRoot which will have the value of the full path to the published folder from earlier like below.

Note: Remember to separate the variables with a comma (,)

image

Using another Function trigger type and adding dependencies

In order to use another Function Trigger type, we need to add in the AzureWebJobsStorage appSettings and any other needed appSetting.

Once you created and published to folder a function of another trigger type, such as a QueueTrigger, we need to add the needed dependency / settings and connection string.

In the solution Explorer expand the WebJobs.Script.WebHost

image

Scroll down and you will see appsettings.json, double click to open it.

image

Now we will add in the AzureWebJobsStorage and QueueConnectionString to the appsettings.json

Note: Your appsettings.json may look a little different then mine.

The AzureWebJobsStorage is the connection string to a Azure blob storage account.

The QueueConnectionString is the connection string used by my Queue Trigger function to connect to the storage queue.

Note: Your appsetting name may be different then mine, depending on what you named it in your function

image

Adding in Additional Logging

To add in additional logging output, we can override the Functions host logging levels.

Note: the below settings are recommended for Debug environment only and should not be used in a fully deployed function or functions host.

 "AzureFunctionsJobHost__logging__fileLoggingMode": "always",
  "AzureFunctionsJobHost__logging__console__isEnabled": "true",
  "AzureFunctionsJobHost__logging__logLevel__default": "Trace",
  "AzureFunctionsJobHost__logging__logLevel__Host.Results": "Trace",
  "AzureFunctionsJobHost__logging__logLevel__Function": "Trace",
  "AzureFunctionsJobHost__logging__logLevel__Host.Aggregator": "Trace",
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published