Azure Function App Redeployment Using Bicep Deletes Functions

I was working on an Azure Function App project with two repositories. The initial repository aimed at creating and configuring resources within Azure, while the second one focused on an Azure function code.

During my work, I observed an issue: every time I redeployed my infrastructure – for instance, to introduce a new resource or modify an existing one – my Azure Functions within the function app would get wiped out. Essentially, Azure was resetting my function app back to its original state, devoid of any functions.

After conducting some research, I unearthed that an Azure Function App operates in two modes for running the functions:

  1. Run functions from deployment package (Bicep)
  2. Run functions from a package file

By default, it utilises the first option, presuming that your functions are incorporated into your function app when creating your resource through Bicep. However, this approach falters when your code gets deployed from a separate pipeline than your function app pipeline.

To enable your function app to run from a package and resolve this issue, add a WEBSITE_RUN_FROM_PACKAGE setting to your function app settings. The value of this settings could be 1 or a URL. In case of 1 , the function app runs from a local package file deployed in the d:\home\data\SitePackages or /home/data/SitePackages folder of your function app. If you opt for a URL, your functions will be executed from that designated location. However, be aware that using this approach could degrade the cold-start performance and isn't recommended.

In Azure DevOps build or release pipeline, if you use "Publish Azure Function" task, it will automatically transfer the zipped code package into your azure function's local storage. By navigating to D:\home\data\SitePackages in the console, you will observe multiple zip files alongside a packagename.txt file containing the current package name.