Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to persist state in Azure Function (the cheap way)?

How can I persist a small amount of data between Azure Function executions? Like in a global variable? The function runs on a Timer Trigger.

I need to store the result of one Azure Function execution and use this as input of the next execution of the same function. What is the cheapest (not necessarily simplest) way of storing data between function executions?

(Currently I'm using the free amount of Azure Functions that everyone gets and now I'd like to save state in a similar free or cheap way.)

like image 736
Heinrich Ulbricht Avatar asked May 25 '17 12:05

Heinrich Ulbricht


2 Answers

There are a couple options - I'd recommend that you store your state in a blob.

You could use a blob input binding to read global state for every execution, and a blob output binding to update that state.

You could also remove the timer trigger and use queues, with the state stored in the queue message and a visibility timeout on the message to set the schedule (i.e next execution time).

Finally, you could use a file on the file system, as it is shared across the function app.

If you can accept the possibility of data loss and only care at the instance level, you can:

  • maintain a static data structure
  • write to instance local storage
like image 138
Matt Mason Avatar answered Oct 03 '22 03:10

Matt Mason


Durable entities are now available to handle persistence of state.

https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-entities?tabs=csharp

like image 44
Lance Avatar answered Oct 03 '22 04:10

Lance