Debugging Azure Functions with LogicApps locally

Azure Functions are a great example of how serverless is conquering the cloud world we live in today. There are also many blogs in how-to-write-functions out there, of which the latest use the precompiled functions, in Visual Studio 2017.

Think of a scenario, where you want to test a LogicApp against your function, but that app obviously cannot connect to localhost. You have two options; You can deploy the Functions app to Azure and use remote debugging or you can use your own localhost, with the use of ngrok.

This blog will explain how to debug locally, when using other services in the cloud.

Azure Functions

First of all, we start off with a very simple function:

Running this will result in something like this:

Default Function running in CLI

That is it; and your function is running locally. Calling it with Chrome will spit out a simple JSON:

Function on localhost

Using Ngrok

Downloading and installing ngrok is extremely easy from their webpage: Using the following line, we will make our localhost on port 7071 (default for Functions) project accessible from the internet:

ngrok command

Please note that I’ve added -host-header due to some issues that could arise when mapping to localhost from the internet.

The ngrok command results in ngrok running:

ngrok running and forwarding

Testing the tunnel

By calling our function, but now using the ngrok hostname provided, we get the exact same output:

Calling function via ngrok tunnel

Bonus Features

If you have any need of testing output of a webhook of any kind; check out Requestbin! This site will let you create a ‘bin’ for your requests, and will show any POST/GET or other data pointed at it. Could be very usefull when debugging output of LogicApps when you use JSON compose and want to inspect your output!

Leave a Reply

Your email address will not be published. Required fields are marked *