TIL #4 - Debug non-HTTP Azure Functions Triggers Locally

Tonight continued some development to include Salesforce authentication and authorization into a side project.  At this point, I have persisted the access and refresh tokens.  I want to use a timer based Azure Function to get the refresh token and update the access tokens as needed for several different OAuth implementations.

The immediate issue I ran into was how to debug these functions locally. I am using the Azure Functions Core Tools v4 and a .NET 5.0 isolated Azure Function.

Since the Functions are running in a isolated process, first I had to attach to the process to debug. In order to debug locally, use the following to start the process and enable debugging.

func host start --dotnet-isolated-debug --verbose

Once the process is running, I can attach to the process using the following configuration in launch.json from Visual Studio Code.

    "version": "0.2.0",
    "configurations": [
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"

And then attach the the process by name or by Id as in the image below.

Once attached, to test a Timer based Function, you can manually run a non HTTP-triggered function by making a POST call using a specific URL format. The linked documentation is great for a released or published Function, but locally you need to call this a little differently.

To invoke the Function locally, make a POST call to the function URL with admin/functions/[function-name] with a Content-Type of application/json and and empty body ({}). I used Postman to initiate my call, but using curl would be similar to the following:

curl  -i -X POST -H "Content-Type:application/json" -d "{}"

This will invoke the a non-HTTP-trigger and you should hit your breakpoint to debug.  

Tweet Post Update Email

My name is Pete Skelly. I write this blog. I am the VP of Technology at ThreeWill, LLC in Alpharetta, GA.

til functions azure dotnet
comments powered by Disqus