Search code examples
azureazure-functionsserverlesstimer-trigger

What is the alternative to global variables in Azure Function Apps?


Lets say I want to have a TimerTrigger function app that executes every 10 seconds and prints an increasing count(1...2...3...), how can I achieve this WITHOUT using environment variable?


Solution

  • You're already using an Azure Storage account for your function. Create a table within that storage account, and increment the counter there. This has the added benefit of persisting across function restarts.

    Since you're using a TimerTrigger, it's implicit that there will only ever be one instance of the function running. If this were not the case, you could end up in a race condition with two or more instances interleaving to incorrectly increment your counter.