How to debug Azure Function locally

One excellent feature that the Azure Functions provides is that we can able to debug our Azure functions with the help of Visual Studio IDE or Visual Studio Code. In this article, we will discuss how to do this using both of the IDEs.

How to debug Azure Function locally in Visual Studio

Now we will discuss how to debug a function app using the Visual Studio 2019.

You can easily debug your Azure function by putting a breakpoint in your Azure function code and then run your Azure Function project by pressing F5. Now you will get the Azure Function URL, you try accessing the URL in any of your favorite Browsers. Once you will put the URL in the Browser and hit the Enter button. You can able to see it will hit the debugger in your code. Let’s check this complete debugging scenario

Now put the debugger in your Azure Function code as shown below

how to debug azure function locally in visual studio 2022

The next step is to run the Azure Function Project by pressing the F5 button and copying the Function URL that you will get after the successful execution of the project. You can able to see below I got the function URL as below

http://localhost:7071/api/HTTPAzureFunction. Copy this URL.

azure function change localhost port

Now Open your Browser and try accessing the URL

Debugging multiple Azure Functions apps at the same time

Now you can able to see the, After you try accessing the Azure Function URL, it hits the breakpoint in the Azure Function code.

how to debug azure function

So we saw, it is really cool to debug the Azure function using Visual Studio 2019. Even it is more interesting to debug multiple function apps in Visual Studio 2019. Let’s check that scenario.

Debugging Multiple Azure Function Apps In Visual Studio 2019

The Visual Studio 2019 can’t launch multiple apps to debug at the same time, But as a workaround what you can try out is, that you can launch one and then attach it to the others. Let’s do that following the below steps

First, Put the breakpoint in both the Functions like below

Here is my first function, where I have put the breakpoint inside the function

debug azure functions visual studio 2019

Below is my second function and I have put the breakpoint there.

how to debug azure function locally in visual studio 2019

Now, the next step is to start the first function app without debugging. Click on the Debug –> Start Without Debugging or press Ctrl + F5.

unable to debug azure function locally

Then, start the second function app with the debugger. Click on the Debug –> Start Debugging or press the F5 button.

how to debug azure function in visual studio

Now you need to attach the debugger to the First Azure Function App. For that, You need to click the Debug –> Attach to Process.

How do I debug Azure function locally?

Now on the Attach to Process window, search for the func.exe. You can see two entries. Select the one that is not greyed out and then click on the Attach button.

How do you debug a function app

Now if you try accessing both the URLs i.e. http://localhost:7071/api/HTTPAzureFunction and http://localhost:5860/api/Function1, you can see it will hit the respective breakpoints inside the Azure Functions.

How to Debug Azure Function locally in Visual Studio Code

Well, we can able to debug the Azure function in Visual Studio Code using simple steps

Put the debugger in the Azure Function as shown below

How to Debug Azure Function in Visual Studio Code

Now Navigate to the Browser where you are trying to Browse the Function URL with the query string parameter value. The URL is http://localhost:7071/api/Mynewfunction2?name=raj. What you need to do is just refresh the Browser or select the URL and hit Enter Button. Now if you go back and check the Function where you put the Breakpoint earlier. It will hit the debugger and if you mouse over on the name parameter, you can able to see the Value as “raj” there, refer to the above screenshot for more clarity.

debug azure functions locally visual studio code

You can also check out the below articles

Wrapping Up

In this Azure article, we discussed how to debug Azure Function locally using Visual Studio and Visual Studio Code. Thanks for the time to read this article !!!