This article demonstrates how to manually run a non HTTP-triggered function via specially formatted HTTP request.
In some contexts, such as during development and troubleshooting, you might need to run "on-demand" an Azure Function that is indirectly triggered. Examples of indirect triggers include functions on a schedule or functions that run as the result of events.
The procedure described in this article is equivalent to using the Test/Run functionality of a function's Code + Test tab in the Azure portal. You can also use Visual Studio Code to manually run functions.
PrerequisitesThe examples in this article use an HTTP test tool. Make sure to choose a tool that keeps your data secure. For more information, see HTTP test tools.
Define the request locationTo run a non HTTP-triggered function, you need a way to send a request to Azure to run the function. The URL used to make this request takes a specific form.
-<slotname>
appended to it. In the previous example, the URL would be myfunctiondemos-staging.azurewebsites.net
for a slot named staging
.admin/functions
. APIs under the /admin/
path are only accessible with authorization.The following considerations apply when making requests to administrator endpoints in your function app:
/admin/
path, you must supply your app's master key in the x-functions-key
header of the request.x-functions-key
header.You can get the master key from either the Azure portal or by using the Azure CLI.
Caution
Due to the elevated permissions in your function app granted by the master key, you shouldn't share this key with third parties or distribute it in an application. The key should only be sent to an HTTPS endpoint.
Navigate to your function app in the Azure portal, select App Keys, and then the _master
key.
In the Edit key section, copy the key value to your clipboard, and then select OK.
Use the az functionapp keys list
â¯command to view the keys, including the master key:
az functionapp keys list --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --slot "<STAGING_SLOT>"
In this example, replace <APP_NAME>
and <RESOURCE_GROUP>
with the name of your function app and resource group, respectively. If you aren't using a staging slot, remove the --slot
parameter. Copy the master key value to your clipboard.
In the Azure portal, navigate top your function app and choose your function.
Select Code + Test, and then select Logs. You see messages from the function logged here when you manually run the function from your HTTP test tool.
In your HTTP test tool, use the request location you defined as the request URL, make sure that the HTTP request method is POST, and include these two request headers:
Key Valuex-functions-key
The master key value pasted from the clipboard. Content-Type
application/json
Make sure that the POST request payload/body is { "input": "<TRIGGER_INPUT>" }
. The specific <TRIGGER_INPUT>
you supply depends on the type of trigger, but it can only be a string, numeric, or boolean value. For services that use JSON payloads, such as Azure Service Bus, the test JSON payload should be escaped and serialized as a string.
If you don't want to pass input data to the function, you must still supply an empty dictionary {}
as the body of the POST request. For more information, see the reference article for the specific non-HTTP trigger.
Send the HTTP POST request. The response should be an HTTP 202 (Accepted) response.
Next, return to your function in the Azure portal. Review the logs and you see messages coming from the manual call to the function.
The way that you access data sent to the trigger depends on the type of trigger and your function language. For more information, see the reference examples for your specific trigger.
Next stepsEvent Grid local testing with viewer web app
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4