Invoking a non-HTTP triggered function locally using the Azure Functions Core Tools Admin API (cardinality: one)
See original GitHub issueIs your question related to a specific version? If so, please specify:
Found Python version 3.8.5 (python3). Azure Functions Core Tools (3.0.2931 Commit hash: d552c6741a37422684f0efab41d541ebad2b2bd2) Function Runtime Version: 3.0.14492.0
What binding does your question apply to, if any? (e.g. Blob Trigger, Event Hub Binding, etc)
Event Hub Trigger Binding (cardinality: one)
Question
Hi there,
we are trying to follow the documentation about how to pass test data to a non-HTTP triggered function to invoke a Python function locally when running within the Azure Functions Core Tools host.
For all kinds of functions other than HTTP triggers and webhooks and Event Grid triggers, you can test your functions locally by calling an administration endpoint. Calling this endpoint with an HTTP POST request on the local server triggers the function.
We are using the EventHub Trigger binding, so the function signature looks like that:
def main(events: List[func.EventHubEvent]):
# Process all events.
for event in events:
pass
Now, we are trying to figure out how exactly to formulate what to put into <trigger_input> in our scenario.
The message body is required to have the following JSON format:
{ "input": "<trigger_input>" }The
<trigger_input>value contains data in a format expected by the function.
When submitting an obviously wrong request like
http http://0.0.0.0:7071/admin/functions/eventHubTrigger input=foobar
the host says
[2020-10-14T15:03:03.439] Executed 'Functions.EventHubTrigger' (Failed, Id=57244492-47f9-4801-a99f-431f64a2cd6e, Duration=86ms)
[2020-10-14T15:03:03.439] System.Private.CoreLib: Exception while executing function: Functions.EventHubTrigger. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'events'. Microsoft.Azure.WebJobs.Host: Binding parameters to complex objects (such as 'Object') uses Json.NET serialization.
[2020-10-14T15:03:03.439] 1. Bind the parameter type as 'string' instead of 'Object' to get the raw values and avoid JSON deserialization, or
[2020-10-14T15:03:03.439] 2. Change the queue payload to be valid json. The JSON parser failed: Error parsing boolean value. Path '', line 1, position 1.
When naively sending real JSON like {"input": [{"device-id": "1"}]}, the host responds with <Response [400]> (Bad Request).
After these observations, we started digging through the source code of the host and the python function worker in order to figure out how to build an appropriate payload reflecting the “real” thing but quickly got lost.
While it is obvious that there will be more efforts required to send a complex object instead of a simple scalar string as outlined within the example
curl --request POST -H "Content-Type:application/json" --data '{"input":"sample queue data"}' http://localhost:7071/admin/functions/QueueTrigger
we are now wondering if that would be possible at all. Maybe you can help us out?
Thank you very much in advance and with kind regards, Andreas.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6

Top Related StackOverflow Question
@amotl If I understood your problem correctly, I think that I found the “magic” format that needs to be submitted through the POST call.
This is how I was able to use the Admin API with Event Hub trigger function:
First thing, the JSON in the POST request needs to follow this pattern:
{"input":"<escaped JSON string>"}. In addition, the escaped JSON string must include"SystemProperties":{}object.If the
"SystemProperties":{}object is missing, the Admin API still returns a 202 response, but in the host logs you can find the following error:Dear @stefanushinardi, @anirudhgarg, @anthonychu and @Hazhzeng,
may I humbly suggest to add the outcome of this research by @kepalas to the aforementioned documentation at Passing test data to a function > Non-HTTP triggered functions?
The gist is:
complexreal-world JSON object as<trigger_input>value, it must be properly escaped."SystemProperties":{}object.With kind regards, Andreas.