You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Run your functions from a package file in Azure
3
-
description: Have the Azure Functions runtime run your functions by mounting a deployment package file that contains your function app project files.
3
+
description: Learn how to configure Azure Functions to run your function app from a deployment package file that contains your function app project.
4
+
ms-service: azure-functions
4
5
ms.topic: conceptual
5
-
ms.date: 02/05/2022
6
+
ms.date: 06/28/2024
6
7
8
+
# Customer intent: As a function developer, I want to understand how to run my function app from a deployment package file, so I can make my function app run faster and easier to update.
7
9
---
8
10
9
11
# Run your functions from a package file in Azure
@@ -14,26 +16,26 @@ This article describes the benefits of running your functions from a package. It
14
16
15
17
## Benefits of running from a package file
16
18
17
-
There are several benefits to running from a package file:
19
+
There are several benefits to running functions from a package file:
18
20
19
21
+ Reduces the risk of file copy locking issues.
20
22
+ Can be deployed to a production app (with restart).
21
-
+You can be certain of the files that are running in your app.
23
+
+Verifies the files that are running in your app.
22
24
+ Improves the performance of [Azure Resource Manager deployments](functions-infrastructure-as-code.md).
23
-
+May reduce cold-start times, particularly for JavaScript functions with large npm package trees.
25
+
+Reduces cold-start times, particularly for JavaScript functions with large npm package trees.
24
26
25
27
For more information, see [this announcement](https://github.com/Azure/app-service-announcements/issues/84).
26
28
27
29
## Enable functions to run from a package
28
30
29
-
To enable your function app to run from a package, 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:
31
+
To enable your function app to run from a package, add a `WEBSITE_RUN_FROM_PACKAGE`app setting to your function app. The `WEBSITE_RUN_FROM_PACKAGE` app setting can have one of the following values:
30
32
31
33
| Value | Description |
32
34
|---------|---------|
33
35
|**`1`**| Indicates that the function app runs from a local package file deployed in the `c:\home\data\SitePackages` (Windows) or `/home/data/SitePackages` (Linux) folder of your function app. |
34
36
|**`<URL>`**| Sets a URL that is the remote location of the specific package file you want to run. Required for functions apps running on Linux in a Consumption plan. |
35
37
36
-
The following table indicates the recommended `WEBSITE_RUN_FROM_PACKAGE`options for deployment to a specific operating system and hosting plan:
38
+
The following table indicates the recommended `WEBSITE_RUN_FROM_PACKAGE`values for deployment to a specific operating system and hosting plan:
37
39
38
40
| Hosting plan | Windows | Linux |
39
41
| --- | --- | --- |
@@ -43,98 +45,91 @@ The following table indicates the recommended `WEBSITE_RUN_FROM_PACKAGE` options
43
45
44
46
## General considerations
45
47
46
-
+ The package file must be .zip formatted. Tar and gzip formats aren't currently supported.
48
+
+ The package file must be .zip formatted. Tar and gzip formats aren't supported.
47
49
+[Zip deployment](#integration-with-zip-deployment) is recommended.
48
50
+ When deploying your function app to Windows, you should set `WEBSITE_RUN_FROM_PACKAGE` to `1` and publish with zip deployment.
49
-
+ When you run from a package, the `wwwroot` folder becomes read-only and you'll receive an error when writing files to this directory. Files are also read-only in the Azure portal.
50
-
+ The maximum size for a deployment package file is currently 1 GB.
51
-
+ You can't use local cache when running from a deployment package.
52
-
+ If your project needs to use remote build, don't use the `WEBSITE_RUN_FROM_PACKAGE` app setting. Instead add the `SCM_DO_BUILD_DURING_DEPLOYMENT=true` deployment customization app setting. For Linux, also add the `ENABLE_ORYX_BUILD=true` setting. To learn more, see [Remote build](functions-deployment-technologies.md#remote-build).
51
+
+ When you run from a package, the `wwwroot` folder is read-only and you receive an error if you write files to this directory. Files are also read-only in the Azure portal.
52
+
+ The maximum size for a deployment package file is 1 GB.
53
+
+ You can't use the local cache when running from a deployment package.
54
+
+ If your project needs to use remote build, don't use the `WEBSITE_RUN_FROM_PACKAGE` app setting. Instead, add the `SCM_DO_BUILD_DURING_DEPLOYMENT=true` deployment customization app setting. For Linux, also add the `ENABLE_ORYX_BUILD=true` setting. For more information, see [Remote build](functions-deployment-technologies.md#remote-build).
53
55
54
56
> [!NOTE]
55
-
> WEBSITE_RUN_FROM_PACKAGEdoes not work with MSDeploy as described [here](https://github.com/projectkudu/kudu/wiki/MSDeploy-VS.-ZipDeploy). You will receive an error during deployment like `ARM-MSDeploy Deploy Failed`. Change /MSDeploy to /ZipDeploy and this error will be resolved.
57
+
> The `WEBSITE_RUN_FROM_PACKAGE` app setting does not work with MSDeploy as described in [MSDeploy VS. ZipDeploy](https://github.com/projectkudu/kudu/wiki/MSDeploy-VS.-ZipDeploy). You will receive an error during deployment, such as `ARM-MSDeploy Deploy Failed`. To resolve this error, hange `/MSDeploy` to `/ZipDeploy`.
This section provides information about how to run your function app from a local package file.
64
66
65
67
### Considerations for deploying from an on-site package
66
68
67
-
+ Using an on-site package is the recommended option for running from the deployment package, except on Linux hosted in a Consumption plan.
69
+
<aname="troubleshooting"></a>
70
+
71
+
+ Using an on-site package is the recommended option for running from the deployment package, except when running on Linux hosted in a Consumption plan.
68
72
+[Zip deployment](#integration-with-zip-deployment) is the recommended way to upload a deployment package to your site.
69
73
+ When not using zip deployment, make sure the `c:\home\data\SitePackages` (Windows) or `/home/data/SitePackages` (Linux) folder has a file named `packagename.txt`. This file contains only the name, without any whitespace, of the package file in this folder that's currently running.
70
74
71
75
### Integration with zip deployment
72
76
73
-
[Zip deployment][Zip deployment for Azure Functions] 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 `c:\home\data\SitePackages` (Windows) or `/home/data/SitePackages` (Linux) folder.
77
+
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 `c:\home\data\SitePackages` (Windows) or `/home/data/SitePackages` (Linux) folder.
74
78
75
-
With the `WEBSITE_RUN_FROM_PACKAGE` app setting value of`1`, the zip deployment APIs copy your package to the `c:\home\data\SitePackages` (Windows) or `/home/data/SitePackages` (Linux) folder instead of extracting the files to `c:\home\site\wwwroot` (Windows) or `/home/site/wwwroot` (Linux). It also creates the `packagename.txt` file. After a restart, the package is mounted to `wwwroot` as a read-only filesystem. For more information about zip deployment, see [Zip deployment for Azure Functions](deployment-zip-push.md).
79
+
When you set the `WEBSITE_RUN_FROM_PACKAGE` app setting value to`1`, the zip deployment APIs copy your package to the `c:\home\data\SitePackages` (Windows) or `/home/data/SitePackages` (Linux) folder instead of extracting the files to `c:\home\site\wwwroot` (Windows) or `/home/site/wwwroot` (Linux). It also creates the `packagename.txt` file. After your function app is automatically restarted, the package is mounted to `wwwroot` as a read-only filesystem. For more information about zip deployment, see [Zip deployment for Azure Functions](deployment-zip-push.md).
76
80
77
81
> [!NOTE]
78
-
> When a deployment occurs, a restart of the function app is triggered. Function executions currently running during the deploy are terminated. Please review [Improve the performance and reliability of Azure Functions](performance-reliability.md#write-functions-to-be-stateless) to learn how to write stateless and defensive functions.
82
+
> When a deployment occurs, a restart of the function app is triggered. Function executions currently running during the deploy are terminated. For information about how to write stateless and defensive functions, sett [Write functions to be stateless](performance-reliability.md#write-functions-to-be-stateless).
79
83
80
-
## Using WEBSITE_RUN_FROM_PACKAGE = URL
84
+
## Use WEBSITE_RUN_FROM_PACKAGE = URL
81
85
82
-
This section provides information about how to run your function app from a package deployed to a URL endpoint. This option is the only one supported for running from a package on Linuxhosted in a Consumption plan.
86
+
This section provides information about how to run your function app from a package deployed to a URL endpoint. This option is the only one supported for running from a Linux-hosted package with a Consumption plan.
83
87
84
88
### Considerations for deploying from a URL
85
89
86
-
<aname="troubleshooting"></a>
87
-
88
-
+ Function apps running on Windows experience a slight increase in [cold start time](event-driven-scaling.md#cold-start) when the application package is deployed to a URL endpoint via `WEBSITE_RUN_FROM_PACKAGE = <URL>`.
90
+
+ Function apps running on Windows experience a slight increase in [cold-start time](event-driven-scaling.md#cold-start) when the application package is deployed to a URL endpoint via `WEBSITE_RUN_FROM_PACKAGE = <URL>`.
89
91
+ When you specify a URL, you must also [manually sync triggers](functions-deployment-technologies.md#trigger-syncing) after you publish an updated package.
90
92
+ The Functions runtime must have permissions to access the package URL.
91
-
+You shouldn't deploy your package to Azure Blob Storage as a public blob. Instead, use a private container with a [Shared Access Signature (SAS)](../storage/common/storage-sas-overview.md) or [use a managed identity](#fetch-a-package-from-azure-blob-storage-using-a-managed-identity) to enable the Functions runtime to access the package.
93
+
+Don't deploy your package to Azure Blob Storage as a public blob. Instead, use a private container with a [shared access signature (SAS)](../storage/common/storage-sas-overview.md) or [use a managed identity](#fetch-a-package-from-azure-blob-storage-using-a-managed-identity) to enable the Functions runtime to access the package.
92
94
+ You must maintain any SAS URLs used for deployment. When an SAS expires, the package can no longer be deployed. In this case, you must generate a new SAS and update the setting in your function app. You can eliminate this management burden by [using a managed identity](#fetch-a-package-from-azure-blob-storage-using-a-managed-identity).
93
95
+ When running on a Premium plan, make sure to [eliminate cold starts](functions-premium-plan.md#eliminate-cold-starts).
94
-
+ When running on a Dedicated plan, make sure you've enabled[Always On](dedicated-plan.md#always-on).
95
-
+ You can use the [Azure Storage Explorer](../vs-azure-tools-storage-manage-with-storage-explorer.md) to upload package files to blob containers in your storage account.
96
+
+ When you're running on a Dedicated plan, ensure you enable[Always On](dedicated-plan.md#always-on).
97
+
+ You can use [Azure Storage Explorer](../vs-azure-tools-storage-manage-with-storage-explorer.md) to upload package files to blob containers in your storage account.
96
98
97
99
### Manually uploading a package to Blob Storage
98
100
99
-
To deploy a zipped package when using the URL option, you must create a .zip compressed deployment package and upload it to the destination. This example deploys to a container in Blob Storage.
101
+
To deploy a zipped package when using the URL option, you must create a .zip compressed deployment package and upload it to the destination. The following procedure deploys to a container in Blob Storage:
100
102
101
103
1. Create a .zip package for your project using the utility of your choice.
102
104
103
-
1. In the [Azure portal](https://portal.azure.com), search for your storage account name or browse for it in storage accounts.
105
+
1. In the [Azure portal](https://portal.azure.com), search for your storage account name or browse for it in the storage accounts list.
104
106
105
107
1. In the storage account, select **Containers** under **Data storage**.
106
108
107
109
1. Select **+ Container** to create a new Blob Storage container in your account.
108
110
109
-
1. In the **New container** page, provide a **Name** (for example, "deployments"), make sure the **Public access level** is **Private**, and select **Create**.
111
+
1. In the **New container** page, provide a **Name** (for example, *deployments*), ensure the **Anonymous access level** is **Private**, and then select **Create**.
110
112
111
-
1. Select the container you created, select **Upload**, browse to the location of the .zip file you created with your project, and select **Upload**.
113
+
1. Select the container you created, select **Upload**, browse to the location of the .zip file you created with your project, and then select **Upload**.
112
114
113
-
1. After the upload completes, choose your uploaded blob file, and copy the URL. You may need to generate a SAS URL if you aren't [using an identity](#fetch-a-package-from-azure-blob-storage-using-a-managed-identity)
115
+
1. After the upload completes, choose your uploaded blob file, and copy the URL. If you aren't [using a managed identity](#fetch-a-package-from-azure-blob-storage-using-a-managed-identity), you might need to generate a SAS URL.
114
116
115
117
1. Search for your function app or browse for it in the **Function App** page.
116
118
117
-
1. In your function app, select**Configurations** under **Settings**.
119
+
1. In your function app, expand**Settings**, and then select **Environment variables**.
118
120
119
-
1. In the **Application Settings** tab, select **New application setting**
121
+
1. In the **App settings** tab, select **+ Add**.
120
122
121
-
1. Enter the value `WEBSITE_RUN_FROM_PACKAGE` for the **Name**, and paste the URL of your package in Blob Storage as the **Value**.
123
+
1. Enter the value `WEBSITE_RUN_FROM_PACKAGE` for the **Name**, and paste the URL of your package in Blob Storage for the **Value**.
122
124
123
-
1. Select **OK**. Then select **Save**>**Continue** to save the setting and restart the app.
125
+
1. Select **Apply**, and then select **Apply**and**Confirm** to save the setting and restart the function app.
124
126
125
-
Now you can run your function in Azure to verify that deployment has succeeded using the deployment package .zip file.
126
-
127
-
The following shows a function app configured to run from a .zip file hosted in Azure Blob storage:
Azure Blob Storage can be configured to [authorize requests with Microsoft Entra ID](/azure/storage/blobs/authorize-access-azure-active-directory?toc=%2fazure%2fstorage%2fblobs%2ftoc.json). This means that instead of generating a SAS key with an expiration, you can instead rely on the application's [managed identity](/azure/app-service/overview-managed-identity). By default, the app's system-assigned identity will be used. If you wish to specify a user-assigned identity, you can set the `WEBSITE_RUN_FROM_PACKAGE_BLOB_MI_RESOURCE_ID` app setting to the resource ID of that identity. The setting can also accept "SystemAssigned" as a value, although this is the same as omitting the setting altogether.
10
+
You can configure Azure Blob Storage to [authorize requests with Microsoft Entra ID](/azure/storage/blobs/authorize-access-azure-active-directory?toc=%2fazure%2fstorage%2fblobs%2ftoc.json). This configuration means that instead of generating a SAS key with an expiration, you can instead rely on the application's [managed identity](/azure/app-service/overview-managed-identity). By default, the app's system-assigned identity is used. If you wish to specify a user-assigned identity, you can set the `WEBSITE_RUN_FROM_PACKAGE_BLOB_MI_RESOURCE_ID` app setting to the resource ID of that identity. The setting can also accept `SystemAssigned` as a value, which is equivalent to omitting the setting.
11
11
12
12
To enable the package to be fetched using the identity:
13
13
14
14
1. Ensure that the blob is [configured for private access](/azure/storage/blobs/anonymous-read-access-configure#set-the-anonymous-access-level-for-a-container).
15
15
16
16
1. Grant the identity the [Storage Blob Data Reader](/azure/role-based-access-control/built-in-roles#storage-blob-data-reader) role with scope over the package blob. See [Assign an Azure role for access to blob data](/azure/storage/blobs/assign-azure-role-data-access) for details on creating the role assignment.
17
17
18
-
1. Set the `WEBSITE_RUN_FROM_PACKAGE` application setting to the blob URL of the package. This will likely be of the form "https://{storage-account-name}.blob.core.windows.net/{container-name}/{path-to-package}" or similar.
18
+
1. Set the `WEBSITE_RUN_FROM_PACKAGE` application setting to the blob URL of the package. This URL is usually of the form `https://{storage-account-name}.blob.core.windows.net/{container-name}/{path-to-package}` or similar.
0 commit comments