Skip to main content

Command Palette

Search for a command to run...

Manually Run a Non-HTTP Triggered Azure Function

Trigger a function that is on a schedule or a function that runs as a result of an action from another resource.

Published
3 min read
Manually Run a Non-HTTP Triggered Azure Function
D

Expert insights on Azure AI architecture and implementation. Real-world solutions for building intelligent enterprise systems.

Introduction

Sometimes, we need to trigger our Azure Functions indirectly. What that means is that we want to trigger a function that is on a schedule or a function that runs as a result of an action from another resource. That action can be from a Blob storage, Service Bus Queue or Topic and other.

In this example, we will take a look at how we can manually run an Azure function that responds to messages from a Service Bus queue.

We will learn how to trigger the function without actually sending a message to the queue.


Examining the Azure function

For this example, we have a very simple Azure function. The code for the function implementation is the following:

namespace FunctionAppSbTrigger
{
    public class Function1
    {
        [FunctionName("MyAwesomeFunction")]
        public void Run([ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")]string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
        }
    }
}

We can see that we have the Service Bus trigger set up that responds to messages from the "myqueue" queue.

Now if we try sending a message to the queue, we can observe that our function executes successfully.

But what if we have a situation where we don't want to or just simply can't send a message to the queue. How can we test our function then?


Manually running the function

To run a non HTTP-triggered function, we can send a simple HTTP POST request.

Now you might be thinking "But Dimitar, this is not even an HTTP triggered function, how can we do that?" and you're right.

We will need to construct a special type of URL to make this request to.

The code of our launchSettings.json file is:

{
  "profiles": {
    "FunctionAppSbTrigger": {
      "commandName": "Project",
      "commandLineArgs": "--port 7289",
      "launchBrowser": false
    }
  }
}

We will construct the new URL using the following information:

  • Host name: The function app's public location

  • Folder path: we have to send the request through the folders admin/functions

  • Function name: name of the function we want to run

The special URL will have the form:

{hostName}/{folderPath}/{functionName}

Replacing these values gives us the final state of the URL:

http://localhost:7289/admin/functions/MyAwesomeFunction

Testing it all out

Next, let's open Postman and do a simple test.

We will set the HTTP method to POST and use the URL from the previous step. We can also specify a body for our request.

if we don't want to pass any data to our function, we still need to pass {} as the body of the request.

In the Headers section set the 'Content-Type' to 'application/json'.

You should have a similar setup as the image below:

Now click on the 'Send' button. Observe that we have successfully triggered our Azure Function without sending any messages to the queue.


The Azure Behind the Madness

Part 6 of 16

Explore the world of Microsoft Azure - from AI and cloud architecture to data and DevOps. The Azure Behind the Madness brings insights, stories, and hands-on guidance for building intelligent, scalable solutions in the cloud.

Up next

AI Agent as a function tool

Use an AI agent as a function tool, so that one agent can call another agent as a tool