1
votes

We are developing the function locally and although we can use the ConfigurationBuilder().AddAzureKeyVault() in the startup to retrieve the Key Vault secrets, we are struggling to make the Queue trigger to get the connection string from the Key Vault. As can be seen below, the connection is currently retrieved from a AzureWebJobsStorage key present in the local.settings.json:

    [FunctionName("myFunction")]
    public async Task MyFunction([QueueTrigger("aQueue", Connection = "AzureWebJobsStorage")] Car myCar)
    {
        await getCarAsync(myCar.Name);
    }

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=....",
2
You can also use "AzureWebJobsStorage": "UseDevelopmentStorage=true" for local dev ?Thomas
@Thomas We are currently developing locally by using the AzureWebJobsStorage stored in the local.settings.json. But the goal is to migrate to Azure Key Vault so the developers don't need to store locally the connection string.user33276346

2 Answers

2
votes

If you're using dependency injection with either FunctionsStartup or IWebJobsStartup you can set the connection string from keyvault like this.

  1. Set the Connection property on the QueueTriggerAttribute to an empty string eg

     [FunctionName("myFunction")]
     public async Task MyFunction([QueueTrigger("aQueue", Connection = "")] Car myCar)
     {
         await getCarAsync(myCar.Name);
     }
    
  1. In your startup class use PostConfigure<QueueAttribute>() to set the connection string value, eg

    public class Startup : FunctionsStartup
    {
      public override void Configure(IFunctionsHostBuilder builder)
      {
         builder.Services.PostConfigure<QueueTriggerAttribute>(x =>
         {
             x.Connection = ReadQueueConnectionStringFromKeyvault();
         });
      }
    }
    

Another alternative to consider is KeyVault references

0
votes

There appears to be a documented issue with triggers, in some cases. (Taken from this article.)

enter image description here