Official Content

You don't need to test Azure Functions in the cloud. Sometimes it may be useful to run them locally to debug any errors. To do so, follow the steps below:

1. Execute the Azure Functions deployment with the Only Package option. It is not necessary to enter valid settings in the credentials (or have Azure CLI) because the deployment package will not be uploaded to the cloud.
The deployment output indicates where the package (zip) has been created.
For example:

Application successfully Packaged to be uploaded to Azure: C:\models\TestDeployAzureFunc\TestDeployAzureFunc\NetCoreModel\Deploy\AZURE_FUNCTIONS\TestWindowsQueue_20230202120948_testqueue.zip

2. Unzip the package to a folder.

3. Use Azure core Tools to run your functions locally.

From a cmd, run:

func start

That starts the Azure functions locally.

HTTP Functions

The URL of each function is indicated in the output of the command line.
You can execute HTTP functions using Postman, for example. Also, if it's called using HTTP GET, just use the web browser.

Other functions such as Timer, Queue or Service Bus-triggered functions

For queue or service bus-triggered functions, you need to set the credentials of the queue or service bus to be run locally.
Otherwise, you'll get the following error when the function starts:

The 'testqueue' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.testqueue'. Microsoft.Azure.WebJobs.Extensions.Storage.Queues: Storage account connection string 'AzureWebJobsqueueConnection' does not exist. Make sure that it is a defined App Setting.

Create a file called local.settings.json in the root directory where you have unzipped the deployment package.
Its contents should be as shown below. Place the connection string of your queue in the AzureWebJobsqueueConnection entry.

{

"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"AzureWebJobsqueueConnection": "DefaultEndpointsProtocol=https;AccountName=storagegx;AccountKey=xxxx==;EndpointSuffix=core.windows.net"
}
}

For Timer triggered functions, the local.settings.json could be as follows:

{

"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"AzureWebJobsStorage": "<here the connection string of a storage account>"
}
}

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant