Reputation: 1739
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=....",
Upvotes: 2
Views: 2014
Reputation: 670
There appears to be a documented issue with triggers, in some cases. (Taken from this article.)
Upvotes: 1
Reputation: 524
If you're using dependency injection with either FunctionsStartup
or IWebJobsStartup
you can set the connection string from keyvault like this.
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);
}
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
Upvotes: 3