Skip to content

Commit df3152e

Browse files
authored
Merge pull request #273012 from diberry/diberry/0422-functions-bindings
Fn Storage v4 - VSCode
2 parents 544d3eb + 9b02473 commit df3152e

7 files changed

+168
-167
lines changed

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

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Connect Azure Functions to Azure SQL Database using Visual Studio Code
33
description: Learn how to connect Azure Functions to Azure SQL Database by adding an output binding to your Visual Studio Code project.
4-
ms.date: 03/04/2024
4+
ms.date: 04/25/2024
55
ms.topic: quickstart
66
author: dzsquared
77
ms.author: drskwier
@@ -30,11 +30,6 @@ Before you begin, you must complete the [quickstart: Create a Python function in
3030

3131
More details on the settings for [Azure SQL bindings and trigger for Azure Functions](functions-bindings-azure-sql.md) are available in the Azure Functions documentation.
3232

33-
::: zone pivot="programming-language-javascript"
34-
>[!NOTE]
35-
>This article currently only supports [Node.js v3 for Functions](./functions-reference-node.md?pivots=nodejs-model-v3).
36-
::: zone-end
37-
3833
## Create your Azure SQL Database
3934

4035
1. Follow the [Azure SQL Database create quickstart](/azure/azure-sql/database/single-database-create-quickstart) to create a serverless Azure SQL Database. The database can be empty or created from the sample dataset AdventureWorksLT.
@@ -105,15 +100,9 @@ Your project has been configured to use [extension bundles](functions-bindings-r
105100

106101
Extension bundles usage is enabled in the host.json file at the root of the project, which appears as follows:
107102

108-
```json
109-
{
110-
"version": "2.0",
111-
"extensionBundle": {
112-
"id": "Microsoft.Azure.Functions.ExtensionBundle",
113-
"version": "[4.*, 5.0.0)"
114-
}
115-
}
116-
```
103+
:::code language="json" source="~/functions-docs-javascript/functions-add-output-binding-sql-cli-v4-programming-model/host.json":::
104+
105+
:::
117106

118107
::: zone-end
119108

@@ -149,33 +138,15 @@ using Microsoft.Azure.Functions.Worker.Extensions.Sql;
149138
```
150139
::: zone-end
151140
::: zone pivot="programming-language-javascript"
152-
Binding attributes are defined directly in the function.json file. Depending on the binding type, additional properties may be required. The [Azure SQL output configuration](./functions-bindings-azure-sql-output.md#configuration) describes the fields required for an Azure SQL output binding.
153-
154-
<!--The extension makes it easy to add bindings to the function.json file.
155-
156-
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:
141+
Binding attributes are defined directly in your code. The [Azure SQL output configuration](./functions-bindings-azure-sql-output.md#configuration) describes the fields required for an Azure SQL output binding.
157142

158-
| Prompt | Value | Description |
159-
| -------- | ----- | ----------- |
160-
| **Select binding direction** | `out` | The binding is an output binding. |
161-
| **Select binding with direction "out"** | `Azure SQL` | The binding is an Azure SQL binding. |
162-
| **The name used to identify this binding in your code** | `toDoItems` | Name that identifies the binding parameter referenced in your code. |
163-
| **The Azure SQL table where data will be written** | `dbo.ToDo` | The name of the Azure SQL table. |
164-
| **Select setting from "local.setting.json"** | `SqlConnectionString` | The name of an application setting that contains the connection string for the Azure SQL database. |
143+
For this `MultiResponse` scenario, you need to add an `extraOutputs` output binding to the function.
165144

166-
A binding is added to the `bindings` array in your function.json, which should look like the following after removing any `undefined` values present. -->
145+
:::code language="javascript" source="~/functions-docs-javascript/functions-add-output-binding-sql-cli-v4-programming-model/src/functions/httpTrigger1.js" range="9-12":::
167146

168-
Add the following to the `bindings` array in your function.json.
147+
Add the following properties to the binding configuration:
169148

170-
```json
171-
{
172-
"type": "sql",
173-
"direction": "out",
174-
"name": "toDoItems",
175-
"commandText": "dbo.ToDo",
176-
"connectionStringSetting": "SqlConnectionString"
177-
}
178-
```
149+
:::code language="javascript" source="~/functions-docs-javascript/functions-add-output-binding-sql-cli-v4-programming-model/src/functions/httpTrigger1.js" range="4-7":::
179150

180151
::: zone-end
181152

@@ -228,20 +199,9 @@ public static OutputType Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "
228199

229200
::: zone-end
230201
::: zone pivot="programming-language-javascript"
202+
Add code that uses the `extraInputs` output binding object on `context` to send a JSON document to the named output binding function, `sendToSql`. Add this code before the `return` statement.
231203

232-
Add code that uses the `toDoItems` output binding object on `context.bindings` to create a new item in the `dbo.ToDo` table. Add this code before the `context.res` statement.
233-
234-
```javascript
235-
if (name) {
236-
context.bindings.toDoItems = JSON.stringify([{
237-
// create a random ID
238-
id: crypto.randomUUID(),
239-
title: name,
240-
completed: false,
241-
url: ""
242-
}]);
243-
}
244-
```
204+
:::code language="javascript" source="~/functions-docs-javascript/functions-add-output-binding-sql-cli-v4-programming-model/src/functions/httpTrigger1.js" range="23-34":::
245205

246206
To utilize the `crypto` module, add the following line to the top of the file:
247207

@@ -251,33 +211,7 @@ const crypto = require("crypto");
251211

252212
At this point, your function should look as follows:
253213

254-
```javascript
255-
const crypto = require("crypto");
256-
257-
module.exports = async function (context, req) {
258-
context.log('JavaScript HTTP trigger function processed a request.');
259-
260-
const name = (req.query.name || (req.body && req.body.name));
261-
const responseMessage = name
262-
? "Hello, " + name + ". This HTTP triggered function executed successfully."
263-
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
264-
265-
if (name) {
266-
context.bindings.toDoItems = JSON.stringify([{
267-
// create a random ID
268-
id: crypto.randomUUID(),
269-
title: name,
270-
completed: false,
271-
url: ""
272-
}]);
273-
}
274-
275-
context.res = {
276-
// status: 200, /* Defaults to 200 */
277-
body: responseMessage
278-
};
279-
}
280-
```
214+
:::code language="javascript" source="~/functions-docs-javascript/functions-add-output-binding-sql-cli-v4-programming-model/src/functions/httpTrigger1.js" :::
281215

282216
::: zone-end
283217

articles/azure-functions/functions-add-output-binding-cosmos-db-vs-code.md

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Connect Azure Functions to Azure Cosmos DB using Visual Studio Code
33
description: Learn how to connect Azure Functions to an Azure Cosmos DB account by adding an output binding to your Visual Studio Code project.
4-
ms.date: 03/04/2024
4+
ms.date: 04/25/2024
55
ms.topic: quickstart
66
zone_pivot_groups: programming-languages-set-functions-temp
77
ms.devlang: csharp
@@ -102,7 +102,18 @@ dotnet add package Microsoft.Azure.Functions.Worker.Extensions.CosmosDB
102102
```
103103

104104
::: zone-end
105-
::: zone pivot="programming-language-javascript,programming-language-python"
105+
106+
::: zone pivot="programming-language-javascript"
107+
108+
Your project has been configured to use [extension bundles](functions-bindings-register.md#extension-bundles), which automatically installs a predefined set of extension packages.
109+
110+
Extension bundles usage is enabled in the *host.json* file at the root of the project, which appears as follows:
111+
112+
:::code language="json" source="~/functions-docs-javascript/functions-add-output-binding-cosmosdb-cli-v4-programming-model/host.json":::
113+
114+
::: zone-end
115+
116+
::: zone pivot="programming-language-python"
106117

107118
Your project has been configured to use [extension bundles](functions-bindings-register.md#extension-bundles), which automatically installs a predefined set of extension packages.
108119

@@ -128,35 +139,15 @@ The `MultiResponse` class allows you to both write to the specified collection i
128139
Specific attributes specify the name of the container and the name of its parent database. The connection string for your Azure Cosmos DB account is set by the `CosmosDbConnectionSetting`.
129140
::: zone-end
130141
::: zone pivot="programming-language-javascript"
131-
Binding attributes are defined directly in the *function.json* file. Depending on the binding type, other properties may be required. The [Azure Cosmos DB output configuration](./functions-bindings-cosmosdb-v2-output.md#configuration) describes the fields required for an Azure Cosmos DB output binding. The extension makes it easy to add bindings to the *function.json* file.
132-
133-
To create a binding, right-click (Ctrl+select 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:
134-
135-
| Prompt | Value | Description |
136-
| -------- | ----- | ----------- |
137-
| **Select binding direction** | `out` | The binding is an output binding. |
138-
| **Select binding with direction "out"** | `Azure Cosmos DB` | The binding is an Azure Cosmos DB binding. |
139-
| **The name used to identify this binding in your code** | `outputDocument` | Name that identifies the binding parameter referenced in your code. |
140-
| **The Azure Cosmos DB database where data will be written** | `my-database` | The name of the Azure Cosmos DB database containing the target container. |
141-
| **Database collection where data will be written** | `my-container` | The name of the Azure Cosmos DB container where the JSON documents will be written. |
142-
| **If true, creates the Azure Cosmos DB database and collection** | `false` | The target database and container already exist. |
143-
| **Select setting from "local.setting.json"** | `CosmosDbConnectionSetting` | The name of an application setting that contains the connection string for the Azure Cosmos DB account. |
144-
| **Partition key (optional)** | *leave blank* | Only required when the output binding creates the container. |
145-
| **Collection throughput (optional)** | *leave blank* | Only required when the output binding creates the container. |
146-
147-
A binding is added to the `bindings` array in your *function.json*, which should look like the following after removing any `undefined` values present:
148-
149-
```json
150-
{
151-
"type": "cosmosDB",
152-
"direction": "out",
153-
"name": "outputDocument",
154-
"databaseName": "my-database",
155-
"containerName": "my-container",
156-
"createIfNotExists": "false",
157-
"connection": "CosmosDbConnectionSetting"
158-
}
159-
```
142+
Binding attributes are defined directly in your function code. The [Azure Cosmos DB output configuration](./functions-bindings-cosmosdb-v2-output.md#configuration) describes the fields required for an Azure Cosmos DB output binding.
143+
144+
For this `MultiResponse` scenario, you need to add an `extraOutputs` output binding to the function.
145+
146+
:::code language="javascript" source="~/functions-docs-javascript/functions-add-output-binding-cosmosdb-cli-v4-programming-model/src/functions/httpTrigger1.js" range="10-13":::
147+
148+
Add the following properties to the binding configuration:
149+
150+
:::code language="javascript" source="~/functions-docs-javascript/functions-add-output-binding-cosmosdb-cli-v4-programming-model/src/functions/httpTrigger1.js" range="3-8":::
160151

161152
::: zone-end
162153
::: zone pivot="programming-language-python"
@@ -179,43 +170,13 @@ Replace the existing Run method with the following code:
179170

180171
::: zone-end
181172
::: zone pivot="programming-language-javascript"
182-
Add code that uses the `outputDocument` output binding object on `context.bindings` to create a JSON document. Add this code before the `context.res` statement.
183-
184-
```javascript
185-
if (name) {
186-
context.bindings.outputDocument = JSON.stringify({
187-
// create a random ID
188-
id: new Date().toISOString() + Math.random().toString().substring(2, 10),
189-
name: name
190-
});
191-
}
192-
```
173+
Add code that uses the `extraInputs` output binding object on `context` to send a JSON document to the named output binding function, `sendToCosmosDb`. Add this code before the `return` statement.
174+
175+
:::code language="javascript" source="~/functions-docs-javascript/functions-add-output-binding-cosmosdb-cli-v4-programming-model/src/functions/httpTrigger1.js" range="24-29":::
193176

194177
At this point, your function should look as follows:
195178

196-
```javascript
197-
module.exports = async function (context, req) {
198-
context.log('JavaScript HTTP trigger function processed a request.');
199-
200-
const name = (req.query.name || (req.body && req.body.name));
201-
const responseMessage = name
202-
? "Hello, " + name + ". This HTTP triggered function executed successfully."
203-
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
204-
205-
if (name) {
206-
context.bindings.outputDocument = JSON.stringify({
207-
// create a random ID
208-
id: new Date().toISOString() + Math.random().toString().substring(2, 10),
209-
name: name
210-
});
211-
}
212-
213-
context.res = {
214-
// status: 200, /* Defaults to 200 */
215-
body: responseMessage
216-
};
217-
}
218-
```
179+
:::code language="javascript" source="~/functions-docs-javascript/src/functions/httpSendToCosmosDb.js" :::
219180

220181
This code now returns a `MultiResponse` object that contains both a document and an HTTP response.
221182

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Connect Azure Functions to Azure Storage using command line tools
33
description: Learn how to connect Azure Functions to an Azure Storage queue by adding an output binding to your command line project.
4-
ms.date: 03/04/2024
4+
ms.date: 04/25/2024
55
ms.topic: quickstart
66
ms.devlang: csharp
77
# ms.devlang: csharp, java, javascript, powershell, python, typescript
@@ -13,11 +13,6 @@ zone_pivot_groups: programming-languages-set-functions
1313

1414
In this article, you integrate an Azure Storage queue with the function and storage account you created in the previous quickstart article. You achieve this integration by using an *output binding* that writes data from an HTTP request to a message in the queue. Completing this article incurs no additional costs beyond the few USD cents of the previous quickstart. To learn more about bindings, see [Azure Functions triggers and bindings concepts](functions-triggers-bindings.md).
1515

16-
::: zone pivot="programming-language-javascript"
17-
>[!NOTE]
18-
>This article currently only supports [Node.js v3 for Functions](./functions-reference-node.md?pivots=nodejs-model-v3).
19-
::: zone-end
20-
2116
## Configure your local environment
2217

2318
::: zone pivot="programming-language-csharp"
@@ -66,12 +61,13 @@ With the queue binding defined, you can now update your function to receive the
6661
[!INCLUDE [functions-add-output-binding-python](../../includes/functions-add-storage-binding-python-v2.md)]
6762
::: zone-end
6863

69-
::: zone pivot="programming-language-javascript"
70-
[!INCLUDE [functions-add-output-binding-js](../../includes/functions-add-output-binding-js.md)]
64+
::: zone pivot="programming-language-javascript"
65+
66+
[!INCLUDE [functions-add-output-binding-js](../../includes/functions-add-output-binding-js-v4.md)]
7167
::: zone-end
7268

7369
::: zone pivot="programming-language-typescript"
74-
[!INCLUDE [functions-add-output-binding-ts](../../includes/functions-add-output-binding-ts.md)]
70+
[!INCLUDE [functions-add-output-binding-ts](../../includes/functions-add-output-binding-ts-v4.md)]
7571
::: zone-end
7672

7773
::: zone pivot="programming-language-powershell"

0 commit comments

Comments
 (0)