In this blog post, I will provide a step by step walk through on how you can debug and run Azure Functions locally in your machine before deploying it to Azure.

Prerequisites

  1. Visual Studio Code
  2. Azure Tools Extension
  3. Azure Functions Core Tools

Step 1 : Installing Azure Functions Extension

AzureToolsExtension

Step 2 : Create a New Project

AzureFnCreateNewProject

2.1 : Select language

Azure Functions can be created using any one of the languages as shown in the image below

AzureFnLanguage

2.2 : Select a template for the Function app

AzureFnTemplate

  • HttpTrigger :  Function gets invoked whenever a Http request is made
  • BlobTrigger : Functions gets invoked whenever a Blob is created in Azure Storage
  • CosmosDBTrigger : Function gets invoked whenever a document is inserted or updated from CosmosDB
  • DurableFunctionsOrchestration : Used to start new orchestrator function or resuming awaiting orchestrator functions
  • EventHubTrigger : Function gets invoked whenever an event is posted in the EventHub
  • QueueTrigger : Function gets invoked whenever a message is posted to the Azure Queue Storage
  • ServiceBusQueueTrigger : Function gets invoked whenever a message is posted to Azure Service Bus Queue
  • ServiceBusTopicTrigger : Function gets invoked whenever a message is posted to Azure Service Topic
  • TimerTrigger : Function gets invoked on a specific schedule

For simplicity of this post, I will be using HttpTrigger

2.3 : Select Name, Namespace & Access

Follow through the steps as below and choose an appropriate Name, namespace & access for the function

AzureFnName

AzureFnNamespace

AzureFnAccess

AzureFnFinalStep

3 : Debug using Azure Functions Core Tools

Once the project is created, VS Code will prompt like below, to resolve the dependencies for this project

AzureFnResolveDependencies

Click on Restore to resolve the dependencies. Once restored, click on the Debug menu item and click on the play button to start debugging.

AzureFnDebugging

If you don’t have Azure Functions Core Tools installed in your machine, you will see the below error :

You must have the Azure Functions Core Tools installed to debug your local functions

To install the required tools, press CTRL + SHIFT + P on windows or CMD + SHIFT + P on Mac to toggle the command palette. Search for Azure Functions :and choose the Azure Functions Core Tools

AzureFnCoreToolsInstallation

Choose the correct runtime version for your Function. In my case, its .netcore v3.1 so I will choose v3

AzureFnRuntimeVersion

That’s it. Now Press F5 or go to Debug and Click Play, you should be able to debug the function. Put a breakpoint anywhere in the functions code and on browsing the function URL, you should see the debugger stopping at the breakpoint. Below is a short video of debugging

AzureFunctionsDebugging