1
votes

Can I deploy one Azure time trigger function from one repo to multiple App Services?

Example:

Currently I have a repo with one Azure function in it (name Function1, runs every few mins).

I have 5 customers, I have a database for each customer and therefore I have 5 connection strings. Each customer requires me to host the function in isolated environment independent from the other customers.

The function "Function1" does the same logic for each of my customers. It just accesses a different database for each using the different connection string.

Therefore, I created 5 App Services: Function1-Customer1, Function1-Customer2, ... to satisfy the "independent environment requirement".

Each App Service has the unique db connection string assigned in the App Settings.

I tried to deploy the "Function1" to all these 5 App Services. However, when then going to see the Log Stream for any of the App Services it seems that only one instance of that function is running, depending on which App Service deployed last.

So for example, if Function1-Customer1 deployed last and I go to Function1-Customer2 or Function1-Customer3 to see the Log Streams, both outputs a conn string of Function1-Customer1. If Function1-Customer2 deployed last then I would see its conn string in all other App Services.

Is it possible to deploy the Function1 to serve all these 5 App Services? Or do I need a different architecture here?

2
It's hard to say without knowing specifics of how you deployed and what the resulting configuration looks like. Screen shots of the Azure portal would help.Noah Stahl
Your requirement should work without any issues. The functions coordinate by obtaining leases in the underlying blob storage. But the lease contains the actual Function App name, so your scenario should not be an issue. I would recommend using multiple storage accounts anyways, just to make it more clear and rule it out.Alex AIT
@AlexAIT I have been thrown into this without any experience so apologise if I don't provide enough info. I had a look and all App Services are assigned to the same storage account. I experimented a bit and found that if I add AzureFunctionsWebHost__hostid with unique identifier to each App Service as an App Setting, then the correct number of functions is running and each is logging a correct connection string. Would that be a viable solution? Or do you think I should just switch to using multiple storage accounts? CheersenrykusLany
I would recommend to use dedicated accounts, since it does not really cost more and you will get more transparency into costs if you decide to add more functions and other features. I have also expanded this discussion into a full answer. You can accept one of the answer or write up your own if you feel your question was solved.Alex AIT

2 Answers

0
votes

The functions coordinate by obtaining leases in the underlying blob storage. If two function apps end up fighting over the same lease, they will block each other even though they are supposed to do different things. You can explore this by looking at the blobs in the underlying storage account an check the "lease" status.

Based on our discussion in the comments, I would recommend to use a dedicated storage account for each function app. I would not recommend AzureFunctionsWebHost__hostid or similar solutions, since it adds more complexity.

0
votes

For each trigger Azure function manages it's own queue in Azure Queue Storage. You can use single function app and trigger 5 different tasks for each customer or you can create separate Azure storage account for each function app.