Skip to content

Commit 6543fac

Browse files
committed
Extend existing tutorial
1 parent cf0b63d commit 6543fac

11 files changed

+244
-361
lines changed

articles/azure-functions/functions-add-output-binding-storage-queue-python.md

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -48,80 +48,13 @@ You can now add the Storage output binding to your project.
4848

4949
## Add an output binding
5050

51-
In Functions, each type of binding requires that a `direction`, a `type`, and a unique `name` be defined in the function.json file. Depending on the binding type, additional properties might be required. The [queue output configuration](functions-bindings-storage-queue.md#output---configuration) describes the fields required for an Azure Storage queue binding.
52-
53-
To create a binding, you add a binding configuration object to the function.json file. Edit the function.json file in your HttpTrigger folder to add an object to the `bindings` array that has these properties:
54-
55-
| Property | Value | Description |
56-
| -------- | ----- | ----------- |
57-
| **`name`** | `msg` | The name that identifies the binding parameter referenced in your code. |
58-
| **`type`** | `queue` | The binding is an Azure Storage queue binding. |
59-
| **`direction`** | `out` | The binding is an output binding. |
60-
| **`queueName`** | `outqueue` | The name of the queue that the binding writes to. When the `queueName` doesn't exist, the binding creates it on first use. |
61-
| **`connection`** | `AzureWebJobsStorage` | The name of an app 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. |
62-
63-
Your function.json file should now look like this example:
64-
65-
```json
66-
{
67-
"scriptFile": "__init__.py",
68-
"bindings": [
69-
{
70-
"authLevel": "function",
71-
"type": "httpTrigger",
72-
"direction": "in",
73-
"name": "req",
74-
"methods": [
75-
"get",
76-
"post"
77-
]
78-
},
79-
{
80-
"type": "http",
81-
"direction": "out",
82-
"name": "$return"
83-
},
84-
{
85-
"type": "queue",
86-
"direction": "out",
87-
"name": "msg",
88-
"queueName": "outqueue",
89-
"connection": "AzureWebJobsStorage"
90-
}
91-
]
92-
}
93-
```
94-
95-
## Add code that uses the output binding
96-
97-
After the `name` is configured, you can start using it to access the binding as a method attribute in the function signature. In the following example, `msg` is an instance of the [`azure.functions.InputStream class`](/python/api/azure-functions/azure.functions.httprequest).
98-
99-
```python
100-
import logging
51+
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.
10152

102-
import azure.functions as func
53+
[!INCLUDE [functions-add-output-binding-json](../../includes/functions-add-output-binding-json.md)]
10354

55+
## Add code that uses the output binding
10456

105-
def main(req: func.HttpRequest, msg: func.Out[func.QueueMessage]) -> str:
106-
107-
name = req.params.get('name')
108-
if not name:
109-
try:
110-
req_body = req.get_json()
111-
except ValueError:
112-
pass
113-
else:
114-
name = req_body.get('name')
115-
116-
if name:
117-
msg.set(name)
118-
return func.HttpResponse(f"Hello {name}!")
119-
else:
120-
return func.HttpResponse(
121-
"Please pass a name on the query string or in the request body",
122-
status_code=400
123-
)
124-
```
57+
[!INCLUDE [functions-add-output-binding-python](../../includes/functions-add-output-binding-python.md)]
12558

12659
When you use an output binding, you don't have to use the Azure Storage SDK code for authentication, getting a queue reference, or writing data. The Functions runtime and queue output binding do those tasks for you.
12760

articles/azure-functions/functions-add-output-binding-storage-queue-vs-code.md

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -67,50 +67,7 @@ In Functions, each type of binding requires a `direction`, `type`, and a unique
6767

6868
### JavaScript
6969

70-
Binding attributes are defined directly in the function.json file. Depending on the binding type, additional properties may be required. The [queue output configuration](functions-bindings-storage-queue.md#output---configuration) describes the fields required for an Azure Storage queue binding. The extension makes it easy to add bindings to the function.json file.
71-
72-
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:
73-
74-
| Prompt | Value | Description |
75-
| -------- | ----- | ----------- |
76-
| **Select binding direction** | `out` | The binding is an output binding. |
77-
| **Select binding with direction...** | `Azure Queue Storage` | The binding is an Azure Storage queue binding. |
78-
| **The name used to identify this binding in your code** | `msg` | Name that identifies the binding parameter referenced in your code. |
79-
| **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. |
80-
| **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. |
81-
82-
A binding is added to the `bindings` array in your function.json file, which should now look like the following example:
83-
84-
```json
85-
{
86-
...
87-
88-
"bindings": [
89-
{
90-
"authLevel": "function",
91-
"type": "httpTrigger",
92-
"direction": "in",
93-
"name": "req",
94-
"methods": [
95-
"get",
96-
"post"
97-
]
98-
},
99-
{
100-
"type": "http",
101-
"direction": "out",
102-
"name": "$return"
103-
},
104-
{
105-
"type": "queue",
106-
"direction": "out",
107-
"name": "msg",
108-
"queueName": "outqueue",
109-
"connection": "AzureWebJobsStorage"
110-
}
111-
]
112-
}
113-
```
70+
[!INCLUDE [functions-add-output-binding-json](../../includes/functions-add-output-binding-json.md)]
11471

11572
### C\# class library
11673

@@ -122,37 +79,7 @@ After the binding is defined, you can use the `name` of the binding to access it
12279

12380
### JavaScript
12481

125-
Add code that uses the `msg` output binding object on `context.bindings` to create a queue message. Add this code before the`context.res` statement.
126-
127-
```javascript
128-
// Add a message to the Storage queue.
129-
context.bindings.msg = "Name passed to the function: " +
130-
(req.query.name || req.body.name);
131-
```
132-
133-
At this point, your function should look as follows:
134-
135-
```javascript
136-
module.exports = async function (context, req) {
137-
context.log('JavaScript HTTP trigger function processed a request.');
138-
139-
if (req.query.name || (req.body && req.body.name)) {
140-
// Add a message to the Storage queue.
141-
context.bindings.msg = "Name passed to the function: " +
142-
(req.query.name || req.body.name);
143-
context.res = {
144-
// status: 200, /* Defaults to 200 */
145-
body: "Hello " + (req.query.name || req.body.name)
146-
};
147-
}
148-
else {
149-
context.res = {
150-
status: 400,
151-
body: "Please pass a name on the query string or in the request body"
152-
};
153-
}
154-
};
155-
```
82+
[!INCLUDE [functions-add-output-binding-js](../../includes/functions-add-output-binding-js.md)]
15683

15784
### C\#
15885

articles/azure-functions/functions-bindings-http-webhook.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ Keys are stored as part of your function app in Azure and are encrypted at rest.
723723

724724
![Manage function keys in the portal.](./media/functions-bindings-http-webhook/manage-function-keys.png)
725725

726-
You may obtain function keys programmatically by using [Key management API](https://github.com/Azure/azure-functions-host/wiki/Key-management-API).
726+
You may obtain function keys programmatically by using [Key management APIs](https://github.com/Azure/azure-functions-host/wiki/Key-management-API).
727727

728728
### API key authorization
729729

@@ -736,8 +736,7 @@ The key can be included in a query string variable named `code`, as above. It ca
736736
You can allow anonymous requests, which do not require keys. You can also require that the master key be used. You change the default authorization level by using the `authLevel` property in the binding JSON. For more information, see [Trigger - configuration](#trigger---configuration).
737737

738738
> [!NOTE]
739-
> When running functions locally, authorization is disabled regardless of the specified authentication level setting. After publishing to Azure, the `authLevel` setting in your trigger is enforced.
740-
739+
> When running functions locally, authorization is disabled regardless of the specified authentication level setting. After publishing to Azure, the `authLevel` setting in your trigger is enforced. Keys are still required when running [locally in a container](functions-create-function-linux-custom-image.md#run-the-image-locally).
741740
742741

743742
### Secure an HTTP endpoint in production

0 commit comments

Comments
 (0)