Azure Function storage account connection string

See Sharp picture See Sharp · Jul 11, 2018 · Viewed 7k times · Source

I have a function app defined like

[StorageAccount("DefaultEndpointsProtocol=...;AccountName=…;AccountKey=...")]
public static class Function1
{
    [FunctionName("Function1")]
    [return: Queue("lets-test-this-out")]
    public static async Task<string> Run([QueueTrigger("lets-test-this-in")] Guid  guid, TraceWriter log)
    {
        await Task.Delay(1000);
        log.Info($"C# Queue trigger function processed: {guid}");
        return Guid.NewGuid().ToString();
    }
}

where lets-test-this-in and lets-test-this-out are the name of existing storage queues under the storage account with connection string "DefaultEndpointsProtocol=...;AccountName=…;AccountKey=..." (copied straight from Access keys - Connection string in the portal). My generated function.json when I publish is like

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "queueTrigger",
      "queueName": "lets-test-this-in",
      "connection": "DefaultEndpointsProtocol=...;AccountName=...;AccountKey=...;",
      "name": "guid"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/FunctionAppTest.dll",
  "entryPoint": "FunctionAppTest.Function1.Run"
}

which the only thing suspicious about that is I don't see [return: Queue("lets-test-this")] being translated to any value there.

Anyways, this isn't working:

  • When I try to test the function in the portal, I see Status: 202 Accepted, but nothing is logged in the output pane.
  • When I drop a message in lets-test-this-in, it does not get picked up.
  • Streaming logs will say [Info] Executing HTTP request and then nothing.

Interestingly though, if I re-publish after removing the [StorageAccount] attribute then I can test in the portal and see in Streaming logs that it is still being executed.

Possibly related is that my local.settings.json is like

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
    }
}

Answer

Mikhail Shilkov picture Mikhail Shilkov · Jul 11, 2018

StorageAccount attribute accepts a name of Application Setting where the connection string is placed, not the connection string itself. E.g.

[StorageAccount("AzureWebJobsStorage")]

Output bindings are not shown in generated function.json - that's confusing but expected.