Manually run a non HTTP-triggered function
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.
Postman is used in the following example, but you can use cURL, Fiddler or any other like tool to send HTTP requests.
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.
Define the request location
To 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.
- Host name: The function app's public location that is made up from the function app's name plus azurewebsites.net or your custom domain. When you work with deployment slots used for staging, the host name portion is the production host name with
-<slotname>
appended to it. In the previous example, the URL would bemyfunctiondemos-staging.azurewebsites.net
for a slot namedstaging
. - Folder path: To access non HTTP-triggered functions via an HTTP request, you have to send the request through the path
admin/functions
. APIs under the/admin/
path are only accessible with authorization. - Function name: The name of the function you want to run.
The following considerations apply when making requests to administrator endpoints in your function app:
- When making requests to any endpoint under the
/admin/
path, you must supply your app's master key in thex-functions-key
header of the request. - When you run locally, authorization isn't enforced and the function's master key isn't required. You can directly call the function omitting the
x-functions-key
header. - When accessing function app endpoints in a deployment slot, make sure you use the slot-specific host name in the request URL, along with the slot-specific master key.
Get the master key
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 should not 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.
Call the function
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 Postman.
Open Postman (or an equivalent HTTP composing tool) and enter the request location in the URL text box.
Make sure that the HTTP method is set to POST, select the Headers tab, and add these two header key-value pairs:
Key Value x-functions-key
The master key value pasted from the clipboard. Content-Type
application/json
Select the Body tab and type
{ "input": "<TRIGGER_INPUT>" }
as the body for the request.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.Select Send.
Postman then reports a status of 202 Accepted.
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 steps
Tagasiside
https://aka.ms/ContentUserFeedback.
Varsti tulekul: 2024. aasta jooksul tühistame GitHubi probleemide funktsiooni sisutagasiside mehhanismina ja asendame selle uue tagasisidesüsteemiga. Lisateabe saamiseks vtEsita ja vaata tagasisidet