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
# Bring dependencies or third party library to Azure Functions
10
10
11
-
In this article, you learn to bring in third-party dependencies, such as json files, binary files, and machine learning models, into your functions apps.
11
+
In this article, you learn to bring in third-party dependencies into your functions apps. Examples of third-party dependencies are json files, binary files and machine learning models.
12
12
13
13
In this article, you learn how to:
14
14
> [!div class="checklist"]
@@ -17,27 +17,10 @@ In this article, you learn how to:
17
17
> [!div class="checklist"]
18
18
> * Bring in dependencies via mounting Azure Fileshare
19
19
::: zone-end
20
-
## Prerequisites
21
-
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio)
22
-
* The Azure Functions Core Tools
23
-
24
-
*[Visual Studio Code](https://code.visualstudio.com/) on one of the [supported platforms](https://code.visualstudio.com/docs/supporting/requirements#_platforms)
25
-
26
-
* The [Azure Functions extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions) for Visual Studio Code.
27
-
::: zone pivot="programming-language-python"
28
-
*[Python versions that are supported by Azure Functions](supported-languages.md#languages-by-runtime-version)
29
-
* Python Azure functions app deployed on Linux consumption plan. [Create your first Azure function in Python](./create-first-function-vs-code-python.md)
30
-
::: zone-end
31
-
::: zone pivot="programming-language-java"
32
-
* The [Java Developer Kit](/azure/developer/java/fundamentals/java-jdk-long-term-support), version 8 or 11.
33
-
*[Apache Maven](https://maven.apache.org), version 3.0 or above.
34
-
* The [Java extension pack](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack)
35
-
* Java Azure functions app deployed on Windows consumption plan. [Create your first Azure function in Java](./create-first-function-vs-code-java.md)
36
-
::: zone-end
37
20
38
21
## Bring in dependencies from the project directory
39
22
::: zone pivot="programming-language-python"
40
-
One of the simplest ways to bring in dependencies is to put the files/artifact together with the functions app code in Functions project directory structure. Here is an example of the directory samples in a Python functions project:
23
+
One of the simplest ways to bring in dependencies is to put the files/artifact together with the functions app code in Functions project directory structure. Here's an example of the directory samples in a Python functions project:
41
24
```
42
25
<project_root>/
43
26
| - my_first_function/
@@ -50,11 +33,11 @@ One of the simplest ways to bring in dependencies is to put the files/artifact t
50
33
| - host.json
51
34
| - local.settings.json
52
35
```
53
-
By putting the dependencies in a folder inside functions app project directory, the dependencies folder will get deployed together with the code. This means that your function code will be able to access the dependencies in the cloud via file system api.
36
+
By putting the dependencies in a folder inside functions app project directory, the dependencies folder will get deployed together with the code. As a result, your function code can access the dependencies in the cloud via file system api.
54
37
55
38
### Accessing the dependencies in your code
56
39
57
-
Here is an example to access and execute ```ffmpeg``` dependency that is put into ```<project_root>/ffmpeg_lib``` directory.
40
+
Here's an example to access and execute ```ffmpeg``` dependency that is put into ```<project_root>/ffmpeg_lib``` directory.
58
41
59
42
60
43
```python
@@ -88,7 +71,7 @@ def main(req: func.HttpRequest,
88
71
::: zone-end
89
72
90
73
::: zone pivot="programming-language-java"
91
-
One of the simplest ways to bring in dependencies is to put the files/artifact together with the functions app code in functions project directory structure. Here is an example of the directory samples in a Java functions project:
74
+
One of the simplest ways to bring in dependencies is to put the files/artifact together with the functions app code in functions project directory structure. Here's an example of the directory samples in a Java functions project:
92
75
```
93
76
<project_root>/
94
77
| - src/
@@ -101,7 +84,7 @@ One of the simplest ways to bring in dependencies is to put the files/artifact t
101
84
| - local.settings.json
102
85
| - pom.xml
103
86
```
104
-
For java specifically, you need to specifically include the artifacts into the build/target folder when copying resources. Here is an example on how to do it in Maven:
87
+
For java specifically, you need to specifically include the artifacts into the build/target folder when copying resources. Here's an example on how to do it in Maven:
105
88
106
89
```xml
107
90
...
@@ -128,11 +111,11 @@ For java specifically, you need to specifically include the artifacts into the b
128
111
</execution>
129
112
...
130
113
```
131
-
By putting the dependencies in a folder inside functions app project directory, the dependencies folder will get deployed together with the code.This means that your function code will be able to access the dependencies in the cloud via file system api.
114
+
By putting the dependencies in a folder inside functions app project directory, the dependencies folder will get deployed together with the code. As a result, your function code can access the dependencies in the cloud via file system api.
132
115
133
116
### Accessing the dependencies in your code
134
117
135
-
Here is an example to access and execute ```ffmpeg``` dependency that is put into ```<project_root>/ffmpeg_lib``` directory.
118
+
Here's an example to access and execute ```ffmpeg``` dependency that is put into ```<project_root>/ffmpeg_lib``` directory.
136
119
137
120
138
121
```java
@@ -186,9 +169,9 @@ public class Function {
186
169
187
170
When running your function app on Linux, there's another way to bring in third-party dependencies. Functions lets you mount a file share hosted in Azure Files. Consider this approach when you want to decouple dependencies or artifacts from your application code.
188
171
189
-
First, you need to create an Azure Storage Account. In the account, you also need to create file share in Azure files. To create these resources, please follow this [guide](../storage/files/storage-how-to-use-files-portal.md)
172
+
First, you need to create an Azure Storage Account. In the account, you also need to create file share in Azure files. To create these resources, follow this [guide](../storage/files/storage-how-to-use-files-portal.md)
190
173
191
-
After the storage account and file share are created, use the [az webapp config storage-account add](/cli/azure/webapp/config/storage-account#az_webapp_config_storage_account_add) command to attach the file share to your functions app, as shown in the following example.
174
+
After you created the storage account and file share, use the [az webapp config storage-account add](/cli/azure/webapp/config/storage-account#az_webapp_config_storage_account_add) command to attach the file share to your functions app, as shown in the following example.
192
175
193
176
```console
194
177
az webapp config storage-account add \
@@ -210,9 +193,9 @@ az webapp config storage-account add \
210
193
| custom-id | Any unique string |
211
194
| storage-type | Only AzureFiles is supported currently |
212
195
| share-name | Pre-existing share |
213
-
| mount-path | Path at which the share will be accessible inside the container. Value has to be of the format `/dir-name` and it cannot start with `/home` |
196
+
| mount-path | Path at which the share will be accessible inside the container. Value has to be of the format `/dir-name` and it can't start with `/home` |
214
197
215
-
Additional commands to modify/delete the file share configuration can be found [here](/cli/azure/webapp/config/storage-account#az-webapp-config-storage-account-update)
198
+
More commands to modify/delete the file share configuration can be found [here](/cli/azure/webapp/config/storage-account#az-webapp-config-storage-account-update)
216
199
217
200
218
201
### Uploading the dependencies to AzureFiles
@@ -222,7 +205,7 @@ One option to upload your dependency into Azure Files is through Azure portal. R
222
205
223
206
### Accessing the dependencies in your code
224
207
225
-
After your dependencies are uploaded in the file share, you can access the dependencies from your code. The mounted share is available at the specified *mount-path*, such as ```/path/to/mount```. You can also access the target directory by using file system APIs.
208
+
After your dependencies are uploaded in the file share, you can access the dependencies from your code. The mounted share is available at the specified *mount-path*, such as ```/path/to/mount```.You can access the target directory by using file system APIs.
226
209
227
210
The following example shows HTTP trigger code that accesses the `ffmpeg` library, which is stored in a mounted file share.
returnfunc.HttpResponse("Unexpected exception happened when executing ffmpeg. Error message:"+ str(e),status_code=200)
251
234
```
252
235
253
-
When you deploy this code to a function app in Azure, you need to [create an app setting](functions-how-to-use-azure-function-app-settings.md#settings) with a key name of `FILE_SHARE_MOUNT_PATH` and value of the mounted file share path, which for this example is `/azure-files-share`. To do local debugging, you need to populate the `FILE_SHARE_MOUNT_PATH` with the file path where your dependencies are stored in your local machine. Here is an example to set `FILE_SHARE_MOUNT_PATH` using `local.settings.json`:
236
+
When you deploy this code to a function app in Azure, you need to [create an app setting](functions-how-to-use-azure-function-app-settings.md#settings) with a key name of `FILE_SHARE_MOUNT_PATH` and value of the mounted file share path, which forthis example is `/azure-files-share`.Todo local debugging, you need to populate the `FILE_SHARE_MOUNT_PATH` with the file path where your dependencies are stored in your local machine. Here's an example to set `FILE_SHARE_MOUNT_PATH` using `local.settings.json`:
254
237
255
238
```json
256
239
{
@@ -269,5 +252,6 @@ When you deploy this code to a function app in Azure, you need to [create an app
269
252
270
253
## Next steps
271
254
272
-
+ [Develop Functions in Visual Studio Code](functions-develop-vs-code.md)
0 commit comments