Skip to content

Commit a3260c4

Browse files
authored
Merge pull request #89761 from ggailey777/linuxpremium-extended
Extend Linux custom container tutorial
2 parents c0dc729 + e3c5308 commit a3260c4

17 files changed

+383
-262
lines changed

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

Lines changed: 9 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,11 @@ Most bindings require a stored connection string that Functions uses to access t
2525

2626
Before you start this article, complete the steps in [part 1 of the Python quickstart](functions-create-first-function-python.md).
2727

28-
## Download the function app settings
29-
30-
In the previous quickstart article, you created a function app in Azure, along with the required Storage account. The connection string for this account is stored securely in app settings in Azure. In this article, you write messages to a Storage queue in the same account. To connect to your Storage account when running the function locally, you must download app settings to the local.settings.json file. Run the following Azure Functions Core Tools command to download settings to local.settings.json, replacing `<APP_NAME>` with the name of your function app from the previous article:
28+
[!INCLUDE [functions-cloud-shell-note](../../includes/functions-cloud-shell-note.md)]
3129

32-
```bash
33-
func azure functionapp fetch-app-settings <APP_NAME>
34-
```
35-
36-
You might need to sign in to your Azure account.
37-
38-
> [!IMPORTANT]
39-
> Because it contains secrets, the local.settings.json file never gets published, and it should be excluded from source control.
30+
## Download the function app settings
4031

41-
You need the value `AzureWebJobsStorage`, which is the Storage account connection string. You use this connection to verify that the output binding works as expected.
32+
[!INCLUDE [functions-app-settings-download-local-cli](../../includes/functions-app-settings-download-local-cli.md)]
4233

4334
## Enable extension bundles
4435

@@ -48,80 +39,13 @@ You can now add the Storage output binding to your project.
4839

4940
## Add an output binding
5041

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
101-
102-
import azure.functions as func
103-
42+
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.
10443

105-
def main(req: func.HttpRequest, msg: func.Out[func.QueueMessage]) -> str:
44+
[!INCLUDE [functions-add-output-binding-json](../../includes/functions-add-output-binding-json.md)]
10645

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')
46+
## Add code that uses the output binding
11547

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-
```
48+
[!INCLUDE [functions-add-output-binding-python](../../includes/functions-add-output-binding-python.md)]
12549

12650
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.
12751

@@ -144,34 +68,11 @@ Next, you use the Azure CLI to view the new queue and verify that a message was
14468

14569
### Set the Storage account connection
14670

147-
Open the local.settings.json file and copy the value of `AzureWebJobsStorage`, which is the Storage account connection string. Set the `AZURE_STORAGE_CONNECTION_STRING` environment variable to the connection string by using this Bash command:
148-
149-
```azurecli-interactive
150-
export AZURE_STORAGE_CONNECTION_STRING=<STORAGE_CONNECTION_STRING>
151-
```
152-
153-
When you set the connection string in the `AZURE_STORAGE_CONNECTION_STRING` environment variable, you can access your Storage account without having to provide authentication each time.
71+
[!INCLUDE [functions-storage-account-set-cli](../../includes/functions-storage-account-set-cli.md)]
15472

15573
### Query the Storage queue
15674

157-
You can use the [`az storage queue list`](/cli/azure/storage/queue#az-storage-queue-list) command to view the Storage queues in your account, as in the following example:
158-
159-
```azurecli-interactive
160-
az storage queue list --output tsv
161-
```
162-
163-
The output from this command includes a queue named `outqueue`, which is the queue that was created when the function ran.
164-
165-
Next, use the [`az storage message peek`](/cli/azure/storage/message#az-storage-message-peek) command to view the messages in this queue, as in this example:
166-
167-
```azurecli-interactive
168-
echo `echo $(az storage message peek --queue-name outqueue -o tsv --query '[].{Message:content}') | base64 --decode`
169-
```
170-
171-
The string returned should be the same as the message you sent to test the function.
172-
173-
> [!NOTE]
174-
> The previous example decodes the returned string from base64. This is because the Queue storage bindings write to and read from Azure Storage as [base64 strings](functions-bindings-storage-queue.md#encoding).
75+
[!INCLUDE [functions-query-storage-cli](../../includes/functions-query-storage-cli.md)]
17576

17677
Now it's time to republish the updated function app to Azure.
17778

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](#tab/nodejs)
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\#](#tab/csharp)
11673

@@ -124,37 +81,7 @@ After the binding is defined, you can use the `name` of the binding to access it
12481

12582
# [JavaScript](#tab/nodejs)
12683

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

15986
# [C\#](#tab/csharp)
16087

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)