|
10 | 10 | |release/2.0|[](https://dev.azure.com/azfunc/Azure%20Functions/_build/latest?definitionId=37&branchName=release%2F2.0)| |
11 | 11 | |v1.x|[](https://ci.appveyor.com/project/appsvc/azure-webjobs-sdk-script-y8o14?branch=v1.x)| |
12 | 12 |
|
13 | | -WebJobs.Script |
| 13 | +Azure Functions Host |
14 | 14 | === |
15 | 15 |
|
16 | | -This repo contains libraries that enable a **light-weight scripting model** for the [Azure WebJobs SDK](http://github.com/Azure/azure-webjobs-sdk). You simply provide job function **scripts** written in various languages (e.g. Javascript/[Node.js](http://nodejs.org), C#, Python, F#, PowerShell, PHP, CMD, BAT, BASH scripts, etc.) along with a simple **function.json** metadata file that indicates how those functions should be invoked, and the scripting library does the work necessary to plug those scripts into the [Azure WebJobs SDK](https://github.com/Azure/azure-webjobs-sdk) runtime. |
17 | | - |
18 | | -These libraries are the runtime used by [Azure Functions](https://azure.microsoft.com/en-us/services/functions/). The runtime builds upon the tried and true [Azure WebJobs SDK](https://github.com/Azure/azure-webjobs-sdk) - this library just layers on top to allow you to "**script the WebJobs SDK**". |
19 | | - |
20 | | -### An important note on language support levels |
21 | | - |
22 | | -While many languages are supported, their level of support differs in important ways, making some languages more suitable than others for certain workloads. These differences are explained according to host version: |
23 | | - |
24 | | -In **V1**, the **first class** languages are C#, F#, and Javascript/Node.js. Functions written in these languages are run **in process** and are suitable for any workload. The remaining languages are considered **experimental**. Functions written in these languages are scripts that are run **out of process**. While there are many scenarios where this is acceptable, it won't be acceptable for high load scenarios where the overhead of a new process for each invocation won't scale. |
25 | | - |
26 | | -In **V2**, running a language **out of process** is no longer considered experimental. Out of process languages include JavaScript/Node.js (GA), Java (GA), Python (GA), and PowerShell (GA). C# and F# are still run **in process**. For more information about Supported Languages, see [this Microsoft Docs page](https://docs.microsoft.com/azure/azure-functions/supported-languages). |
27 | | - |
28 | | -### Code Examples |
29 | | - |
30 | | -Here's a simple Node.js function that receives a queue message and writes that message to Azure Blob storage: |
31 | | - |
32 | | -```javascript |
33 | | -module.exports = function (context, workItem) { |
34 | | - context.log('Node.js queue trigger function processed work item ', workItem.id); |
35 | | - context.bindings.receipt = workItem; |
36 | | - context.done(); |
37 | | -} |
38 | | -``` |
39 | | - |
40 | | -And here's the corresponding **function.json** file which includes a trigger **input binding** that instructs the runtime to invoke this function whenever a new queue message is added to the `samples-workitems` queue: |
41 | | - |
42 | | -```javascript |
43 | | -{ |
44 | | - "bindings": [ |
45 | | - { |
46 | | - "type": "queueTrigger", |
47 | | - "direction": "in", |
48 | | - "queueName": "samples-workitems" |
49 | | - }, |
50 | | - { |
51 | | - "type": "blob", |
52 | | - "name": "receipt", |
53 | | - "direction": "out", |
54 | | - "path": "samples-workitems/{id}" |
55 | | - } |
56 | | - ] |
57 | | -} |
58 | | -``` |
59 | | - |
60 | | -The `receipt` blob **output binding** that was referenced in the code above is also shown. Note that the blob binding path `samples-workitems/{id}` includes a parameter `{id}`. The runtime will bind this to the `id` property of the incoming JSON message. Functions can be just a single script file, or can include additional files/content. For example, a Node.js function might include a node_modules folder, multiple .js files, etc. A PowerShell function might include and load additional companion scripts. |
61 | | - |
62 | | -Here's a PowerShell script that uses the **same function definition**, writing the incoming messages to blobs (it could process/modify the message in any way): |
63 | | - |
64 | | -```powershell |
65 | | -param([string] $workItem, $TriggerMetadata) |
66 | | -Write-Host "PowerShell queue trigger function processed work item: $workItem" |
67 | | -Push-OutputBinding -Name receipt -Value $workItem |
68 | | -``` |
69 | | - |
70 | | -And here's a Python function for the same function definition doing the same thing: |
71 | | - |
72 | | -```python |
73 | | -import os |
74 | | - |
75 | | -# read the queue message and write to stdout |
76 | | -workItem = open(os.environ['input']).read() |
77 | | -message = "Python script processed work item '{0}'".format(workItem) |
78 | | -print(message) |
79 | | - |
80 | | -# write to the output binding |
81 | | -f = open(os.environ['receipt'], 'w') |
82 | | -f.write(workItem) |
83 | | -``` |
84 | | - |
85 | | -Note that for all script types other than Node.js, binding inputs are made available to the script via environment variables, and output logs is written via STDOUT. You can see more script language [examples here](http://github.com/Azure/azure-webjobs-sdk-script/tree/master/sample). |
86 | | - |
87 | | -The samples also includes a canonical [image resize sample](http://github.com/Azure/azure-webjobs-sdk-script/tree/master/sample/ResizeImage). This sample demonstrates both input and output bindings. Here's the **function.json**: |
88 | | - |
89 | | -```javascript |
90 | | -{ |
91 | | - "bindings": [ |
92 | | - { |
93 | | - "type": "blobTrigger", |
94 | | - "name": "original", |
95 | | - "direction": "in", |
96 | | - "path": "images-original/{name}" |
97 | | - }, |
98 | | - { |
99 | | - "type": "blob", |
100 | | - "name": "resized", |
101 | | - "direction": "out", |
102 | | - "path": "images-resized/{name}" |
103 | | - } |
104 | | - ] |
105 | | -} |
106 | | -``` |
107 | | - |
108 | | -When the script is triggered by a new image in `images-original`, the input binding reads the original image from blob storage (binding to the `name` property from the blob path), sets up the output binding, and invokes the script. Here's the batch script (resize.bat): |
109 | | - |
110 | | -```batch |
111 | | -.\Resizer\Resizer.exe %original% %resized% 200 |
112 | | -``` |
113 | | - |
114 | | -Using Resizer.exe which is part of the function content, the operation is a simple one-liner. The bound paths set up by the runtime are passed into the resizer, the resizer processes the image, and writes the result to `%resized%`. The ouput binding uploads the image written to `%resized%` to blob storage. |
115 | | - |
116 | | -On startup, the script runtime loads all scripts and metadata files and begins listening for events (e.g. new Queue messages, Blobs, etc.). Functions are invoked automatically when their trigger events are received. Virtually all of the WebJobs SDK triggers (including [Extensions](http://github.com/Azure/azure-webjobs-sdk-extensions)) are available for scripting. Most of the configuration options found in the WebJobs SDK can also be specified via json metadata. |
117 | | - |
118 | | -When hosted in an [Azure Web App](http://azure.microsoft.com/en-us/services/app-service/web/) this means there is **no compilation + publish step required**. Simply by modifying a script file, the runtime will load the new script content + metadata, and the changes are **live**. Scripts and their metadata can be modified quickly on the fly in a browser editor (e.g. in a first class UI or in the [Kudu Console](http://github.com/projectkudu/kudu/wiki/Kudu-console)) and the changes take effect immediately. |
119 | | - |
120 | | -The Script library is available as a Nuget package (**Microsoft.Azure.WebJobs.Script**). Currently this package is available on the [App Service Myget feed](http://github.com/Azure/azure-webjobs-sdk/wiki/%22Nightly%22-Builds). |
121 | | - |
122 | | -Please see the [Wiki](https://github.com/Azure/azure-webjobs-sdk-script/wiki) for more information on how to use and deploy the library, and also please log any issues/feedback on our [issues list](https://github.com/Azure/azure-webjobs-sdk-script/issues) and we'll investigate. |
| 16 | +This repo contains code for the runtime host used by the [Azure Functions](https://docs.microsoft.com/en-us/azure/azure-functions/) service. The Azure Functions runtime builds upon the [Azure WebJobs SDK](https://github.com/Azure/azure-webjobs-sdk) to provide a hosting platform for functions written in many different [languages](https://docs.microsoft.com/en-us/azure/azure-functions/supported-languages) and supporting a wide variety of [triggers and bindings](https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?tabs=csharp#supported-bindings). |
123 | 17 |
|
124 | 18 | ### License |
125 | 19 |
|
|
0 commit comments