Paul Michaels
Paul Michaels

Reputation: 16705

Output binding and generation of function.json

I'm trying to create an Azure function that will output to a table. I'm using the Azure Function App, and so, as I currently understand it, the function.json is generated for me by the SDK. My function definition is as follows:

public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, 
        TraceWriter log,
        [StorageAccount("table_storage")] ICollector<TableItem> outputTable)

I've defined TableItem as a class that inherits from TableEntity. When I deploy this and look at the generated function.json, it doesn't mention the output parameter binding:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.7",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "methods": [
        "post"
      ],
      "authLevel": "function",
      "name": "req"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/FunctionApp5.dll",
  "entryPoint": "FunctionApp5.DeliveryComplete.Run"
}

If I run this from Visual Studio, I get the following error:

Cannot bind parameter 'outputTable' to type ICollector`1

I have a few questions about this behaviour: the first and main one is, why is function.json not showing the output binding? Secondly, I understand why this can't be edited when you deploy from VS, but is there a way to manage the bindings without guesswork (I came across using ICollector in this post), but I can't find anywhere else that says it should or shouldn't be there.

Finally, how does (or does) running this from the desktop interact with the published function: does it connect to the published version of the function, or does it generate the function.json locally?

Upvotes: 2

Views: 679

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35144

  1. That's a common source of confusion, but input and output bindings are not visible in generated function.json, only trigger does. They will still work normally.

  2. If you are trying to write to Table Storage, you should use Table attribute instead of StorageAccount. ICollector is mentioned in Azure Table storage bindings for Azure Functions.

  3. When running locally, the files stay locally and run in local runtime, without deployment to Azure. They might still interact with real Azure services via bindings.

Upvotes: 4

Related Questions