Skip to content

Commit f71b827

Browse files
authored
Merge pull request #11547 from alexkarcher-msft/master
Added Functions external table binding docs
2 parents 46ba139 + a829d94 commit f71b827

8 files changed

+261
-60
lines changed

articles/azure-functions/TOC.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#### [Notification Hubs](functions-bindings-notification-hubs.md)
3131
#### [Mobile Apps](functions-bindings-mobile-apps.md)
3232
#### [External file](functions-bindings-external-file.md)
33+
#### [External table](functions-bindings-external-table.md)
3334
### [Define Functions proxies](functions-proxies.md)
3435
### [Create a function app from the Azure portal](functions-create-function-app-portal.md)
3536
### [Perform a scheduled clean-up task](functions-scenario-database-table-cleanup.md)

articles/azure-functions/functions-bindings-external-file.md

+58-60
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ ms.author: alkarche
1818

1919
---
2020
# Azure Functions External File bindings (Preview)
21-
This article explains how to configure and use external file bindings in Azure functions. Azure functions supports trigger, input, and output bindings for external file.
21+
This article shows how to manipulate files from different SaaS providers (e.g. OneDrive, Dropbox) within your function utilizing built-in bindings. Azure functions supports trigger, input, and output bindings for external file.
2222

23-
External file bindings allow functions to access files hosted outside of Azure. This binding creates new API connections, or uses existing API connections from your Function App's resource group.
23+
This binding creates API connections to SaaS providers, or uses existing API connections from your Function App's resource group.
2424

2525
[!INCLUDE [intro](../../includes/functions-bindings-intro.md)]
2626

@@ -261,11 +261,62 @@ deserialize the file data using that type:
261261
* `CloudBlockBlob`
262262
* `CloudPageBlob`
263263

264-
<a name="inputsample"></a>
265264

266-
## Input sample
265+
<a name="output"></a>
266+
267+
## External File output binding
268+
The Azure external file output binding enables you to write files to an external folder in your function.
269+
270+
The external file output for a function uses the following JSON objects in the `bindings` array of function.json:
271+
272+
```json
273+
{
274+
"name": "<Name of output parameter in function signature>",
275+
"type": "apiHubFile",
276+
"direction": "out",
277+
"path": "<Path of input file - see below>",
278+
"connection": "<name of external file connection>"
279+
}
280+
```
281+
282+
Note the following:
283+
284+
* `path` must contain the folder name and the file name to write to. For example, if you have a [queue trigger](functions-bindings-storage-queue.md)
285+
in your function, you can use `"path": "samples-workitems/{queueTrigger}"` to point to a file in the `samples-workitems` folder with a name that
286+
matches the file name specified in the trigger message.
287+
288+
<a name="outputusage"></a>
289+
290+
## Output usage
291+
In C# functions, you bind to the output file by using the named `out` parameter in your function signature, like `out <T> <name>`,
292+
where `T` is the data type that you want to serialize the data into, and `paramName` is the name you specified in the
293+
[output binding](#output). In Node.js functions, you access the output file using `context.bindings.<name>`.
294+
295+
You can write to the output file using any of the following types:
296+
297+
* Any [Object](https://msdn.microsoft.com/library/system.object.aspx) - useful for JSON-serialization.
298+
If you declare a custom output type (e.g. `out OutputType paramName`), Azure Functions attempts to serialize object
299+
into JSON. If the output parameter is null when the function exits, the Functions runtime creates a file as
300+
a null object.
301+
* String - (`out string paramName`) useful for text file data. the Functions runtime creates a file only if the
302+
string parameter is non-null when the function exits.
303+
304+
In C# functions you can also output to any of the following types:
305+
306+
* `TextWriter`
307+
* `Stream`
308+
* `CloudFileStream`
309+
* `ICloudFile`
310+
* `CloudBlockFile`
311+
* `CloudPageFile`
312+
313+
<a name="outputsample"></a>
314+
315+
<a name="sample"></a>
316+
317+
## Input + Output sample
267318
Suppose you have the following function.json, that defines a [Storage queue trigger](functions-bindings-storage-queue.md),
268-
n external file input, and an external file output:
319+
an external file input, and an external file output:
269320

270321
```json
271322
{
@@ -303,7 +354,7 @@ See the language-specific sample that copies the input file to the output file.
303354

304355
<a name="incsharp"></a>
305356

306-
### Input usage in C# #
357+
### Usage in C# #
307358

308359
```cs
309360
public static void Run(string myQueueItem, string myInputFile, out string myOutputFile, TraceWriter log)
@@ -323,7 +374,7 @@ public static void Run(string myQueueItem, string myInputFile, out string myOutp
323374

324375
<a name="innodejs"></a>
325376

326-
### Input usage in Node.js
377+
### Usage in Node.js
327378

328379
```javascript
329380
module.exports = function(context) {
@@ -333,58 +384,5 @@ module.exports = function(context) {
333384
};
334385
```
335386

336-
<a name="output"></a>
337-
338-
## External File output binding
339-
The Azure external file output binding enables you to write files to an external folder in your function.
340-
341-
The external file output for a function uses the following JSON objects in the `bindings` array of function.json:
342-
343-
```json
344-
{
345-
"name": "<Name of output parameter in function signature>",
346-
"type": "apiHubFile",
347-
"direction": "out",
348-
"path": "<Path of input file - see below>",
349-
"connection": "<name of external file connection>"
350-
}
351-
```
352-
353-
Note the following:
354-
355-
* `path` must contain the folder name and the file name to write to. For example, if you have a [queue trigger](functions-bindings-storage-queue.md)
356-
in your function, you can use `"path": "samples-workitems/{queueTrigger}"` to point to a file in the `samples-workitems` folder with a name that
357-
matches the file name specified in the trigger message.
358-
359-
<a name="outputusage"></a>
360-
361-
## Output usage
362-
In C# functions, you bind to the output file by using the named `out` parameter in your function signature, like `out <T> <name>`,
363-
where `T` is the data type that you want to serialize the data into, and `paramName` is the name you specified in the
364-
[output binding](#output). In Node.js functions, you access the output file using `context.bindings.<name>`.
365-
366-
You can write to the output file using any of the following types:
367-
368-
* Any [Object](https://msdn.microsoft.com/library/system.object.aspx) - useful for JSON-serialization.
369-
If you declare a custom output type (e.g. `out OutputType paramName`), Azure Functions attempts to serialize object
370-
into JSON. If the output parameter is null when the function exits, the Functions runtime creates a file as
371-
a null object.
372-
* String - (`out string paramName`) useful for text file data. the Functions runtime creates a file only if the
373-
string parameter is non-null when the function exits.
374-
375-
In C# functions you can also output to any of the following types:
376-
377-
* `TextWriter`
378-
* `Stream`
379-
* `CloudFileStream`
380-
* `ICloudFile`
381-
* `CloudBlockFile`
382-
* `CloudPageFile`
383-
384-
<a name="outputsample"></a>
385-
386-
## Output sample
387-
See [input sample](#inputsample).
388-
389387
## Next steps
390388
[!INCLUDE [next steps](../../includes/functions-bindings-next-steps.md)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
---
2+
title: Azure Functions External Table binding (Preview) | Microsoft Docs
3+
description: Using External Table bindings in Azure Functions
4+
services: functions
5+
documentationcenter: ''
6+
author: alexkarcher-msft
7+
manager: erikre
8+
editor: ''
9+
10+
ms.assetid:
11+
ms.service: functions
12+
ms.workload: na
13+
ms.tgt_pltfrm: na
14+
ms.devlang: multiple
15+
ms.topic: article
16+
ms.date: 04/12/2017
17+
ms.author: alkarche
18+
19+
---
20+
# Azure Functions External Table binding (Preview)
21+
This article shows how to manipulate tabular data on SaaS providers (e.g. Sharepoint, Dynamics) within your function with built-in bindings. Azure Functions supports input, and output bindings for external tables.
22+
23+
[!INCLUDE [intro](../../includes/functions-bindings-intro.md)]
24+
25+
## API Connections
26+
27+
Table bindings leverage external API connections to authenticate with 3rd party SaaS providers.
28+
29+
When assigning a binding you can either create a new API connection or use an existing API connection within the same resource group
30+
31+
### Supported API Connections (Table)s
32+
33+
|Connector|Trigger|Input|Output|
34+
|:-----|:---:|:---:|:---:|
35+
|[DB2](https://docs.microsoft.com/azure/connectors/connectors-create-api-db2)||x|x
36+
|[Dynamics 365 for Operations](https://ax.help.dynamics.com/wiki/install-and-configure-dynamics-365-for-operations-warehousing/)||x|x
37+
|[Dynamics 365](https://docs.microsoft.com/azure/connectors/connectors-create-api-crmonline)||x|x
38+
|[Dynamics NAV](https://msdn.microsoft.com/library/gg481835.aspx)||x|x
39+
|[Google Sheets](https://docs.microsoft.com/azure/connectors/connectors-create-api-googledrive)||x|x
40+
|[Informix](https://docs.microsoft.com/azure/connectors/connectors-create-api-informix)||x|x
41+
|[Dynamics 365 for Financials](https://docs.microsoft.com/azure/connectors/connectors-create-api-crmonline)||x|x
42+
|[MySQL](https://docs.microsoft.com/azure/store-php-create-mysql-database)||x|x
43+
|[Oracle Database](https://docs.microsoft.com/azure/connectors/connectors-create-api-oracledatabase)||x|x
44+
|[Common Data Service](https://docs.microsoft.com/common-data-service/entity-reference/introduction)||x|x
45+
|[Salesforce](https://docs.microsoft.com/azure/connectors/connectors-create-api-salesforce)||x|x
46+
|[SharePoint](https://docs.microsoft.com/azure/connectors/connectors-create-api-sharepointonline)||x|x
47+
|[SQL Server](https://docs.microsoft.com/azure/connectors/connectors-create-api-sqlazure)||x|x
48+
|[Teradata](http://www.teradata.com/products-and-services/azure/products/)||x|x
49+
|UserVoice||x|x
50+
|Zendesk||x|x
51+
52+
53+
> [!NOTE]
54+
> External Table connections can also be used in [Azure Logic Apps](https://docs.microsoft.com/azure/connectors/apis-list)
55+
56+
### Creating an API connection: step by step
57+
58+
1. Create a function > custom function
59+
![Create a custom function](./media/functions-bindings-storage-table/create-custom-function.jpg)
60+
1. Scenario `Experimental` > `ExternalTable-CSharp` template > Create a new `External Table connection`
61+
![Choose table input template](./media/functions-bindings-storage-table/create-template-table.jpg)
62+
1. Choose your SaaS provider > choose/create a connection
63+
![Configure SaaS connection](./media/functions-bindings-storage-table/authorize-API-connection.jpg)
64+
1. Select your API connection > create the function
65+
![Create table function](./media/functions-bindings-storage-table/table-template-options.jpg)
66+
1. Select `Integrate` > `External Table`
67+
1. Configure the connection to use your target table. These settings will very between SaaS providers. They are outline below in [data source settings](#datasourcesettings)
68+
![Configure table](./media/functions-bindings-storage-table/configure-API-connection.jpg)
69+
70+
## Usage
71+
72+
This example connects to a table named "Contact" with Id, LastName, and FirstName columns. The code lists the Contact entities in the table and logs the first and last names.
73+
74+
### Bindings
75+
```json
76+
{
77+
"bindings": [
78+
{
79+
"type": "manualTrigger",
80+
"direction": "in",
81+
"name": "input"
82+
},
83+
{
84+
"type": "apiHubTable",
85+
"direction": "in",
86+
"name": "table",
87+
"connection": "ConnectionAppSettingsKey",
88+
"dataSetName": "default",
89+
"tableName": "Contact",
90+
"entityId": "",
91+
}
92+
],
93+
"disabled": false
94+
}
95+
```
96+
`entityId` must be empty for table bindings.
97+
98+
`ConnectionAppSettingsKey` identifies the app setting that stores the API connection string. The app setting is created automatically when you add an API connection in the integrate UI.
99+
100+
A tabular connector provides data sets, and each data set contains tables. The name of the default data set is “default.” The titles for a dataset and a table in various SaaS providers are listed below:
101+
102+
|Connector|Dataset|Table|
103+
|:-----|:---|:---|
104+
|**SharePoint**|Site|SharePoint List
105+
|**SQL**|Database|Table
106+
|**Google Sheet**|Spreadsheet|Worksheet
107+
|**Excel**|Excel file|Sheet
108+
109+
<!--
110+
See the language-specific sample that copies the input file to the output file.
111+
112+
* [C#](#incsharp)
113+
* [Node.js](#innodejs)
114+
115+
-->
116+
<a name="incsharp"></a>
117+
118+
### Usage in C# #
119+
120+
```cs
121+
#r "Microsoft.Azure.ApiHub.Sdk"
122+
#r "Newtonsoft.Json"
123+
124+
using System;
125+
using Microsoft.Azure.ApiHub;
126+
127+
//Variable name must match column type
128+
//Variable type is dynamically bound to the incoming data
129+
public class Contact
130+
{
131+
public string Id { get; set; }
132+
public string LastName { get; set; }
133+
public string FirstName { get; set; }
134+
}
135+
136+
public static async Task Run(string input, ITable<Contact> table, TraceWriter log)
137+
{
138+
//Iterate over every value in the source table
139+
ContinuationToken continuationToken = null;
140+
do
141+
{
142+
//retreive table values
143+
var contactsSegment = await table.ListEntitiesAsync(
144+
continuationToken: continuationToken);
145+
146+
foreach (var contact in contactsSegment.Items)
147+
{
148+
log.Info(string.Format("{0} {1}", contact.FirstName, contact.LastName));
149+
}
150+
151+
continuationToken = contactsSegment.ContinuationToken;
152+
}
153+
while (continuationToken != null);
154+
}
155+
```
156+
157+
<!--
158+
<a name="innodejs"></a>
159+
160+
### Usage in Node.js
161+
162+
```javascript
163+
module.exports = function(context) {
164+
context.log('Node.js Queue trigger function processed', context.bindings.myQueueItem);
165+
context.bindings.myOutputFile = context.bindings.myInputFile;
166+
context.done();
167+
};
168+
```
169+
-->
170+
<a name="datasourcesettings"></a>
171+
## Data Source Settings
172+
173+
### SQL Server
174+
175+
The script to create and populate the Contact table is below. dataSetName is “default.”
176+
177+
```sql
178+
CREATE TABLE Contact
179+
(
180+
Id int NOT NULL,
181+
LastName varchar(20) NOT NULL,
182+
FirstName varchar(20) NOT NULL,
183+
CONSTRAINT PK_Contact_Id PRIMARY KEY (Id)
184+
)
185+
GO
186+
INSERT INTO Contact(Id, LastName, FirstName)
187+
VALUES (1, 'Bitt', 'Prad')
188+
GO
189+
INSERT INTO Contact(Id, LastName, FirstName)
190+
VALUES (2, 'Glooney', 'Ceorge')
191+
GO
192+
```
193+
194+
### Google Sheets
195+
In Google Docs, create a spreadsheet with a worksheet named `Contact`. The connector cannot use the spreadsheet display name. The internal name (in bold) needs to be used as dataSetName, for example: `docs.google.com/spreadsheets/d/`**`1UIz545JF_cx6Chm_5HpSPVOenU4DZh4bDxbFgJOSMz0`**
196+
Add the column names `Id`, `LastName`, `FirstName` to the first row, then populate data on subsequent rows.
197+
198+
### Salesforce
199+
dataSetName is “default.”
200+
201+
## Next steps
202+
[!INCLUDE [next steps](../../includes/functions-bindings-next-steps.md)]

0 commit comments

Comments
 (0)