Run your Azure Functions from a package file

In Azure, you can run your functions directly from a deployment package file in your function app. The other option is to deploy your files in the d:\home\site\wwwroot directory of your function app.

This article describes the benefits of running your functions from a package. It also shows how to enable this functionality in your function app.

Important

When deploying your functions to a Linux function app in a Premium plan, you should always run from the package file and publish your app using the Azure Functions Core Tools.

Benefits of running from a package file

There are several benefits to running from a package file:

  • Reduces the risk of file copy locking issues.
  • Can be deployed to a production app (with restart).
  • You can be certain of the files that are running in your app.
  • Improves the performance of Azure Resource Manager deployments.
  • May reduce cold-start times, particularly for JavaScript functions with large npm package trees.

For more information, see this announcement.

Enabling functions to run from a package

To enable your function app to run from a package, you just add a WEBSITE_RUN_FROM_PACKAGE setting to your function app settings. The WEBSITE_RUN_FROM_PACKAGE setting can have one of the following values:

Value Description
1 Recommended for function apps running on Windows. Run from a package file in the d:\home\data\SitePackages folder of your function app. If not deploying with zip deploy, this option requires the folder to also have a file named packagename.txt. This file contains only the name of the package file in folder, without any whitespace.
<url> Location of a specific package file you want to run. When using Blob storage, you should use a private container with a Shared Access Signature (SAS) to enable the Functions runtime to access to the package. You can use the Azure Storage Explorer to upload package files to your Blob storage account.

Caution

When running a function app on Windows, the external URL option yields worse cold-start performance. When deploying your function app to Windows, you should set WEBSITE_RUN_FROM_PACKAGE to 1 and publish with zip deployment.

The following shows a function app configured to run from a .zip file hosted in Azure Blob storage:

WEBSITE_RUN_FROM_ZIP app setting

Note

Currently, only .zip package files are supported.

Integration with zip deployment

Zip deployment is a feature of Azure App Service that lets you deploy your function app project to the wwwroot directory. The project is packaged as a .zip deployment file. The same APIs can be used to deploy your package to the d:\home\data\SitePackages folder. With the WEBSITE_RUN_FROM_PACKAGE app setting value of 1, the zip deployment APIs copy your package to the d:\home\data\SitePackages folder instead of extracting the files to d:\home\site\wwwroot. It also creates the packagename.txt file. The function app is then run from the package after a restart, and wwwroot becomes read-only. For more information about zip deployment, see Zip deployment for Azure Functions.

Adding the WEBSITE_RUN_FROM_PACKAGE setting

There are several ways that you can add, update, and delete function app settings:

Troubleshooting

  • Run From Package makes wwwroot read-only, so you will receive an error when writing files to this directory.
  • Tar and gzip formats are not supported.
  • This feature does not compose with local cache.
  • For improved cold-start performance, use the local Zip option (WEBSITE_RUN_FROM_PACKAGE=1).

Next steps