I'm trying to create an Azure Function (.NET core) to retrieve a SaS from a storage account and am struggling to understand why I cannot access the storage.
The function signature:
public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
[StorageAccount("StorageConnectionString")] StorageAccount storage,
ILogger log)
When running it, there's this error:
Error indexing method 'GetBlobSaS' Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'storage' to type StorageAccount. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
If I'm creating the storage account reference directly it works fine:
var storage = StorageAccount.NewFromConnectionString(System.Environment.GetEnvironmentVariable("StorageConnectionString"));
What am I misunderstanding or doing wrong?
The error that you are getting is an error that the Function runtime does not understand the method-signature. The [StorageAccount] attribute is requiring a CloudStorageAccount.
So change the signature to:
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[StorageAccount("StorageConnectionString")] CloudStorageAccount storage,
ILogger log)
{
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With