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
Step 1 : Installing Azure Functions Extension
Step 2 : Create a New Project
2.1 : Select language
Azure Functions can be created using any one of the languages as shown in the image below
2.2 : Select a template for the Function app
HttpTrigger
: Function gets invoked whenever a Http request is madeBlobTrigger
: Functions gets invoked whenever a Blob is created in Azure StorageCosmosDBTrigger
: Function gets invoked whenever a document is inserted or updated from CosmosDBDurableFunctionsOrchestration
: Used to start new orchestrator function or resuming awaiting orchestrator functionsEventHubTrigger
: Function gets invoked whenever an event is posted in the EventHubQueueTrigger
: Function gets invoked whenever a message is posted to the Azure Queue StorageServiceBusQueueTrigger
: Function gets invoked whenever a message is posted to Azure Service Bus QueueServiceBusTopicTrigger
: Function gets invoked whenever a message is posted to Azure Service TopicTimerTrigger
: 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
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
Click on Restore
to resolve the dependencies. Once restored, click on the Debug
menu item and click on the play button to start debugging.
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
Choose the correct runtime version for your Function. In my case, its .netcore v3.1 so I will choose v3
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