×
  1. Home
  2. Knowledge Base
  3. Automation
  4. Automation Course Part 11 – debugging Azure Functions locally

Automation Course Part 11 – debugging Azure Functions locally

Now that you have your CI/CD pipeline set up, you can write code locally in VSCode, and only publish it to your repository and to Azure once you’ve gotten it working.

This final article in our 11-part series outlines some of the tools and techniques you’ll need in order to get started building, testing, and debugging your functions locally.

Step 1: Install the Azure Functions Core Tools

Before you can debug Azure functions locally, you need to install the Azure Functions Core Tools. These tools provide a local development experience that is similar to what you would experience in the cloud. You can install the Azure Functions Core Tools using npm or the MSI package.  [Develop Azure Functions locally using Core Tools | Microsoft Learn]

npm install -g azure-functions-core-tools@3--unsafe-perm true

Step 2: Create a local.settings.json file

The local.settings.json file contains environment variables that are used by the Azure functions runtime. You should create a local.settings.json file in the root directory of your function app project. The contents of the file will be a set of key-value pairs similar to the below. Any Azure Application Settings, including secrets, can be stored here.

{"IsEncrypted":false,"Values":{
"AzureWebJobsStorage":"UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME":"node",
"MyCustomSetting":"MyValue"
}
}

Step 3: Set breakpoints in your code

To debug your Azure functions locally, you need to set breakpoints in your code. You can set breakpoints in VSCode by clicking on the line number where you want to set the breakpoint. Sometimes, it helps to use Wait-Debugger in case breakpoints are skipped.

Step 4: Start the debugger

To start the debugger, you need to open the debug view in VSCode and click the “Start Debugging” button. This will launch the Azure Functions runtime and attach the debugger to it. You should see a message in the VSCode console that says “Listening on http://localhost:7071”.

Step 5: Trigger your function

To trigger your function, you can use the Azure Functions extension for VSCode or a tool like Postman (Postman is great for this if you need to customize a payload). When your function is triggered, the debugger will stop at the breakpoints you set in your code.

Step 6: Debug your function

Once the debugger has stopped at a breakpoint, you can use the VSCode debugger tools to inspect variables, evaluate expressions, and step through your code. You can also use the VSCode console to log messages and view the output of your function.

Related Articles