0

I have a queue trigger (for example):

        [FunctionName("Handle-Invoice")]
        [StorageAccount("StorageAccountConnectionString")]
        public async Task InvoiceQueueTrigger(
            [QueueTrigger("invoice-queue")] CloudQueueMessage cloudMessage,
            ExecutionContext context,
            ILogger log)
        {
            // Async code which might need access to the storage account for the queue
        }

Where StorageAccountConnectionString is defined in the function's config.

I'm wondering if there's a way to implicitly access the value of the connection string defined in the StorageAccount attribute?

I know I can access the value directly from either the environment or configuration but it'd be good to access the value either by a binding or some other method.

Thanks.

Nick
  • 25,026
  • 7
  • 51
  • 83
  • 1
    Do you mean this? `[QueueTrigger("myqueue-items", Connection = "StorageAccountConnectionString")]CloudQueueMessage cloudMessage` – Cindy Pau Feb 01 '21 at 12:09
  • 1
    There's no built in way, other than as you say via IConfiguration binding or GetEnvironmentVariable. You could however write your own custom binding attributes to provide it. If you bind to CloudQueue instead you can get *some* of the info from the Uri/StorageUri/ServiceClient properties. Also note with the pending updates to Azure functions (and the current "beta" version supporting net5) the azure types have switched to the latest Azure.Storage.Queued SDK which has a totally different API and better access to properties of interest (should that be an option for you) – pinkfloydx33 Feb 01 '21 at 12:16
  • @pinkfloydx33 thanks for the suggestions. I'll maybe just wait and see what the score is if/when we upgrade to the newer Functions, probably not going to be able to use a Beta version in our codebase. – Nick Feb 01 '21 at 16:48
  • @BowmanZhu thanks for commenting. No, I mean getting access to the actual value of the Storage Account connection string within the body of the function rather than as part of the binding. In other words, some way of access the value of `Connection` in your example. – Nick Feb 01 '21 at 16:49
  • 1
    Since net5 isnt LTS there won't be an official azure functions update until Net6. They do however offer a way to host the runtime yourself using updated net5 pieces, which is what I refer to as 'beta'. In any event, you should be able to write a custom binding attribute and provider very easily, to get the connection string shoved into an appropriately decorated parameter. . There are plenty of examples out there, a couple in the azure sdk repo I think... Otherwise some blog posts – pinkfloydx33 Feb 01 '21 at 17:26
  • Thanks @pinkfloydx33 I'll take a look. – Nick Feb 04 '21 at 12:46

0 Answers0