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
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-add-output-binding-storage-queue-vs-code.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,14 +89,22 @@ Now, you can add the storage output binding to your project.
89
89
90
90
## Add an output binding
91
91
92
-
In Functions, each type of binding requires a `direction`, `type`, and a unique `name` to be defined in the *function.json* file. The way you define these attributes depends on the language of your function app.
93
92
94
-
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-powershell"
93
+
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-powershell"
94
+
95
+
In Functions, each type of binding requires a `direction`, `type`, and unique `name`. The way you define these attributes depends on the language of your function app.
In Functions, each type of binding requires a `direction`, `type`, and a unique `name`. The way you define these attributes depends on your Python programming model.
Copy file name to clipboardExpand all lines: includes/functions-add-output-binding-cli.md
+53-16Lines changed: 53 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
author: ggailey777
3
3
ms.service: azure-functions
4
4
ms.topic: include
5
-
ms.date: 06/10/2022
5
+
ms.date: 02/09/2023
6
6
ms.author: glenga
7
7
ms.custom: devdivchpfy22
8
8
---
@@ -12,25 +12,69 @@ ms.custom: devdivchpfy22
12
12
13
13
Although a function can have only one trigger, it can have multiple input and output bindings, which lets you connect to other Azure services and resources without writing custom integration code.
14
14
::: zone-end
15
-
::: zone pivot="programming-language-python,programming-language-javascript,programming-language-powershell,programming-language-typescript"
15
+
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-typescript"
16
+
16
17
You declare these bindings in the *function.json* file in your function folder. From the previous quickstart, your *function.json* file in the *HttpExample* folder contains two bindings in the `bindings` collection:
18
+
19
+
::: zone-end
20
+
21
+
::: zone pivot="programming-language-python"
22
+
23
+
The way you declare binding attributes depends on your Python programming model.
24
+
25
+
# [v1](#tab/v1)
26
+
27
+
You declare these bindings in the *function.json* file in your function folder. From the previous quickstart, your *function.json* file in the *HttpExample* folder contains two bindings in the `bindings` collection:
Each binding has at least a type, a direction, and a name. In the above example, the first binding is of type `httpTrigger` with the direction `in`. For the `in` direction, `name` specifies the name of an input parameter that's sent to the function when invoked by the trigger.
32
+
33
+
The second binding in the collection is of type `http` with the direction `out`, in which case the special `name` of `$return` indicates that this binding uses the function's return value rather than providing an input parameter.
34
+
35
+
To write to an Azure Storage queue from this function, add an `out` binding of type `queue` with the name `msg`, as shown in the code below:
In this case, `msg` is given to the function as an output argument. For a `queue` type, you must also specify the name of the queue in `queueName` and provide the *name* of the Azure Storage connection (from *local.settings.json* file) in `connection`.
40
+
41
+
# [v2](#tab/v2)
42
+
43
+
Binding attributes are defined directly in the *function_app.py* file as decorators. From the previous quickstart, your *function_app.py* file already contains one decorator-based binding:
The `route` decorator adds HttpTrigger and HttpOutput binding to the function, which enables your function be triggered when http requests hit the specified route.
56
+
57
+
To write to an Azure Storage queue from this function, add the `queue_output` decorator to your function code:
In the decorator, `arg_name` identifies the binding parameter referenced in your code, `queue_name` is name of the queue that the binding writes to, and `connection` is the name of an application setting that contains the connection string for the Storage account. In quickstarts you use the same storage account as the function app, which is in the `AzureWebJobsStorage` setting (from *local.settings.json* file). When the `queue_name` doesn't exist, the binding creates it on first use.
64
+
65
+
---
66
+
17
67
::: zone-end
18
68
19
69
::: zone pivot="programming-language-javascript,programming-language-typescript"
::: zone pivot="programming-language-python,programming-language-javascript, programming-language-powershell, programming-language-typescript"
32
-
Each binding has at least a type, a direction, and a name. In the above example, the first binding is of type `httpTrigger` with the direction `in`. For the `in` direction, `name` specifies the name of an input parameter that's sent to the function when invoked by the trigger.
33
-
::: zone-end
34
78
35
79
::: zone pivot="programming-language-javascript,programming-language-typescript"
36
80
The second binding in the collection is named `res`. This `http` binding is an output binding (`out`) that is used to write the HTTP response.
@@ -40,13 +84,6 @@ To write to an Azure Storage queue from this function, add an `out` binding of t
The second binding in the collection is of type `http` with the direction `out`, in which case the special `name` of `$return` indicates that this binding uses the function's return value rather than providing an input parameter.
45
-
46
-
To write to an Azure Storage queue from this function, add an `out` binding of type `queue` with the name `msg`, as shown in the code below:
::: zone pivot="programming-language-python,programming-language-javascript,programming-language-powershell,programming-language-typescript"
96
+
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-typescript"
60
97
In this case, `msg` is given to the function as an output argument. For a `queue` type, you must also specify the name of the queue in `queueName` and provide the *name* of the Azure Storage connection (from *local.settings.json* file) in `connection`.
Copy file name to clipboardExpand all lines: includes/functions-add-output-binding-json.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ms.date: 09/23/2019
6
6
ms.author: glenga
7
7
---
8
8
9
-
Binding attributes are defined directly in the function.json file. Depending on the binding type, additional properties may be required. The [queue output configuration](../articles/azure-functions/functions-bindings-storage-queue-output.md#configuration) describes the fields required for an Azure Storage queue binding. The extension makes it easy to add bindings to the function.json file.
9
+
Binding attributes are defined in the *function.json* file for a given function. Depending on the binding type, additional properties may be required. The [queue output configuration](../articles/azure-functions/functions-bindings-storage-queue-output.md#configuration) describes the fields required for an Azure Storage queue binding. The extension makes it easy to add bindings to the *function.json* file.
10
10
11
11
To create a binding, right-click (Ctrl+click on macOS) the `function.json` file in your HttpTrigger folder and choose **Add binding...**. Follow the prompts to define the following binding properties for the new binding:
12
12
@@ -18,6 +18,6 @@ To create a binding, right-click (Ctrl+click on macOS) the `function.json` file
18
18
|**The queue to which the message will be sent**|`outqueue`| The name of the queue that the binding writes to. When the *queueName* doesn't exist, the binding creates it on first use. |
19
19
|**Select setting from "local.setting.json"**|`AzureWebJobsStorage`| The name of an application setting that contains the connection string for the Storage account. The `AzureWebJobsStorage` setting contains the connection string for the Storage account you created with the function app. |
20
20
21
-
A binding is added to the `bindings` array in your function.json, which should look like the following:
21
+
A binding is added to the `bindings` array in your *function.json*, which should look like the following:
Update *HttpExample\\function_app.py* to match the following code, add the `msg` parameter to the function definition and `msg.set(name)` under the `if name:` statement:
logging.info('Python HTTP trigger function processed a request.')
29
+
30
+
name = req.params.get('name')
31
+
ifnot name:
32
+
try:
33
+
req_body = req.get_json()
34
+
exceptValueError:
35
+
pass
36
+
else:
37
+
name = req_body.get('name')
38
+
39
+
if name:
40
+
msg.set(name)
41
+
return func.HttpResponse(f"Hello {name}!")
42
+
else:
43
+
return func.HttpResponse(
44
+
"Please pass a name on the query string or in the request body",
45
+
status_code=400
46
+
)
47
+
```
48
+
49
+
The `msg` parameter is an instance of the [`azure.functions.Out class`](/python/api/azure-functions/azure.functions.out). The `set` method writes a string message to the queue. In this case, it's the name passed to the function in the URL query string.
Binding attributes are defined by decorating specific function code in the *function_app.py* file. You use the `queue_output` decorator to add an [Azure Queue storage output binding](/azure/azure-functions/functions-bindings-triggers-python#azure-queue-storage-output-binding).
10
+
11
+
By using the `queue_output` decorator, the binding direction is implicitly 'out' and type is Azure Storage Queue. Add the following decorator to your function code in *function_app.py*:
In this code, `arg_name` identifies the binding parameter referenced in your code, `queue_name` is name of the queue that the binding writes to, and `connection` is the name of an application setting that contains the connection string for the Storage account. In quickstarts you use the same storage account as the function app, which is in the `AzureWebJobsStorage` setting. When the `queue_name` doesn't exist, the binding creates it on first use.
0 commit comments