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/logic-apps/logic-apps-azure-functions.md
+70-38Lines changed: 70 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
title: Call Azure Functions from logic app workflows
3
-
description: Run your own code in workflows created with Azure Logic Apps by calling Azure Functions.
2
+
title: Call Azure Functions from workflows
3
+
description: Create and run code from workflows in Azure Logic Apps by calling Azure Functions.
4
4
services: logic-apps
5
5
ms.suite: integration
6
6
ms.reviewer: estfan, azla
@@ -9,7 +9,7 @@ ms.date: 02/01/2022
9
9
ms.custom: devx-track-js
10
10
---
11
11
12
-
# Create and run your own code from workflows in Azure Logic Apps by using Azure Functions
12
+
# Create and run code from workflows in Azure Logic Apps using Azure Functions
13
13
14
14
When you want to run code that performs a specific job in your logic app workflow, you can create a function by using [Azure Functions](../azure-functions/functions-overview.md). This service helps you create Node.js, C#, and F# functions so you don't have to build a complete app or infrastructure to run code. You can also [call logic app workflows from inside an Azure function](#call-logic-app). Azure Functions provides serverless computing in the cloud and is useful for performing certain tasks, for example:
15
15
@@ -31,23 +31,23 @@ You can also run code snippets without using Azure Functions. For more informati
31
31
32
32
If you don't have a function app, [create your function app first](../azure-functions/functions-get-started.md). You can then create your function either outside your logic app in the Azure portal or [from inside your logic app](#create-function-designer) in the workflow designer.
33
33
34
-
* When working with logic apps, the same requirements apply to both function apps and functions, existing or new:
34
+
* When working with logic app resources, the same requirements apply to both function apps and functions, existing or new:
35
35
36
-
* Your function app and logic app must use the same Azure subscription.
36
+
* Your function app resource and logic app resource must use the same Azure subscription.
37
37
38
38
* New function apps must use either the .NET or JavaScript as the runtime stack. When you add a new function to existing function apps, you can select either C# or JavaScript.
39
39
40
40
* Your function uses the **HTTP trigger** template.
41
41
42
-
The HTTP trigger template can accept content that has `application/json` type from your logic app. When you add a function to your logic app, the workflow designer shows custom functions that are created from this template within your Azure subscription.
42
+
The HTTP trigger template can accept content that has `application/json` type from your logic app workflow. When you add a function to your workflow, the designer shows custom functions that are created from this template within your Azure subscription.
43
43
44
44
* Your function doesn't use custom routes unless you've defined an [OpenAPI definition](../azure-functions/functions-openapi-definition.md) ([Swagger file](https://swagger.io/)).
45
45
46
46
* If you have an OpenAPI definition for your function, the workflow designer gives you a richer experience when your work with function parameters. Before your logic app workflow can find and access functions that have OpenAPI definitions, [set up your function app by following these steps](#function-swagger).
47
47
48
-
* Either a [Consumption or Standard](logic-apps-overview.md#resource-type-and-host-environment-differences) logic app resource and workflow where you want to use the function, including a [trigger](../logic-apps/logic-apps-overview.md#logic-app-concepts) as the first step in your workflow.
48
+
* Either a [Consumption or Standard](logic-apps-overview.md#resource-type-and-host-environment-differences) logic app resource and workflow where you want to use the function.
49
49
50
-
Before you can add actions that run functions, your workflowmust start with a trigger. If you're new to logic apps, review [What is Azure Logic Apps](../logic-apps/logic-apps-overview.md) and [Quickstart: Create your first logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md).
50
+
Before you can add an action that runs a function in your workflow, the workflow must start with a trigger as the first step. If you're new to logic app workflows, review [What is Azure Logic Apps](logic-apps-overview.md) and [Quickstart: Create your first logic app](quickstart-create-first-logic-app-workflow.md).
51
51
52
52
<aname="function-swagger"></a>
53
53
@@ -69,7 +69,7 @@ For a richer experience when you work with function parameters in the workflow d
69
69
70
70
## Access property values inside HTTP requests
71
71
72
-
Webhook functions can accept HTTP requests as inputs and pass those requests to other functions. For example, although Logic Apps has [functions that convert DateTime values](../logic-apps/workflow-definition-language-functions-reference.md), this basic sample JavaScript function shows how you can access a property inside a request object that's passed to the function and perform operations on that property value. To access properties inside objects, this example uses the [dot (.) operator](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Property_accessors):
72
+
Webhook functions can accept HTTP requests as inputs and pass those requests to other functions. For example, although Azure Logic Apps has [functions that convert DateTime values](workflow-definition-language-functions-reference.md), this basic sample JavaScript function shows how you can access a property inside a request object that's passed to the function and perform operations on that property value. To access properties inside objects, this example uses the [dot (.) operator](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Property_accessors):
73
73
74
74
```javascript
75
75
functionconvertToDateString(request, response){
@@ -227,82 +227,114 @@ To call existing functions from your logic app workflow, you can add functions l
227
227
228
228
<aname="call-logic-app"></a>
229
229
230
-
## Call logic apps from functions
230
+
## Call workflows from functions
231
231
232
-
When you want to trigger a logic app from inside a function, the logic app must start with a trigger that provides a callable endpoint. For example, you can start the logic app with the **HTTP**, **Request**, **Azure Queues**, or **Event Grid** trigger. Inside your function, send an HTTP POST request to the trigger's URL, and include the payload you want that logic app to process. For more information, review [Call, trigger, or nest logic apps](logic-apps-http-endpoint.md).
232
+
When you want to trigger a logic app workflow from inside a function, the workflow must start with a trigger that provides a callable endpoint. For example, you can start the workflow with the **HTTP**, **Request**, **Azure Queues**, or **Event Grid** trigger. Inside your function, send an HTTP POST request to the trigger's URL, and include the payload you want that workflow to process. For more information, review [Call, trigger, or nest logic app workflows](logic-apps-http-endpoint.md).
233
233
234
234
<aname="enable-authentication-functions"></a>
235
235
236
-
## Enable authentication for functions
236
+
## Enable authentication for function calls
237
237
238
-
Your logic app can use a [managed identity](../active-directory/managed-identities-azure-resources/overview.md) (formerly known as Managed Service Identity or MSI), if you want to easily authenticate access to resources protected by Azure Active Directory (Azure AD) without having to sign in and provide credentials or secrets. Azure manages this identity for you and helps secure your credentials because you don't have to provide or rotate secrets. Learn more about [Azure services that support managed identities for Azure AD authentication](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md#azure-services-that-support-azure-ad-authentication).
238
+
Your logic app resource can use a [managed identity](../active-directory/managed-identities-azure-resources/overview.md) (formerly known as Managed Service Identity or MSI) for authentication. A managed identity helps you authenticate access to resources protected by Azure Active Directory (Azure AD) without having to sign in and provide credentials or secrets. Azure manages this identity for you and helps secure your credentials because you don't have to provide or rotate secrets. Learn more about [Azure services that support managed identities for Azure AD authentication](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md#azure-services-that-support-azure-ad-authentication).
239
239
240
-
If you set up your logic app to use the system-assigned identity or a manually created, user-assigned identity, the function in your logic app workflow can also use that same identity for authentication. For more information about authentication support for functions in logic app workflows, review [Add authentication to outbound calls](logic-apps-securing-a-logic-app.md#add-authentication-outbound).
240
+
If you set up your logic app to use the system-assigned identity or a manually created, user-assigned identity, your logic app can use that identity to authenticate access to your function. For more information about authentication support for Azure function calls in logic app workflows, review [Add authentication to outbound calls](logic-apps-securing-a-logic-app.md#add-authentication-outbound).
241
241
242
-
To set up and use the managed identity with your function, follow these steps:
242
+
To set up and use your logic app's managed identity to call your function, follow these steps:
243
243
244
244
1. Enable the managed identity on your logic app resource, and set up that identity's access to the target resource. For more information, review [Authenticate access to Azure resources by using managed identities in Azure Logic Apps](create-managed-service-identity.md).
245
245
246
246
1. Enable authentication in your function and function app by following these steps:
247
247
248
-
*[Set up anonymous authentication in your function](#set-authentication-function-app)
249
-
*[Set up Azure AD authentication in your function app](#set-azure-ad-authentication)
248
+
1.[Set up anonymous authentication for your function](#set-authentication-function-app).
249
+
250
+
1.[Set up Azure AD authentication for your function app](#set-azure-ad-authentication).
250
251
251
252
<aname="set-authentication-function-app"></a>
252
253
253
-
### Set up anonymous authentication in your function
254
+
## Set up anonymous authentication for your function
255
+
256
+
To set up and use your logic app's managed identity to authenticate function calls, you must set your function's authentication level to anonymous. Otherwise, your logic app workflow throws a **BadRequest** error.
254
257
255
-
To use your logic app's managed identity in your function, you must set your function's authentication level to anonymous. Otherwise, your logic app workflow throws a "BadRequest" error.
258
+
1. In the [Azure portal](https://portal.azure.com), find and select your functionapp.
256
259
257
-
1. In the [Azure portal](https://portal.azure.com), find and select your function app. These steps use "FabrikamFunctionApp" as the example function app.
260
+
The following steps use an example function app named **FabrikamFunctionApp**.
258
261
259
262
1. On the function app resource menu, under **Development tools**, select **Advanced Tools** > **Go**.
260
263
261
264

262
265
263
-
1. After the Kudu Services page opens, on the Kudu website's title bar, from the **Debug Console** menu, select **CMD**.
266
+
1. After the **Kudu Services** page opens, on the Kudu website's title bar, from the **Debug Console** menu, select **CMD**.
264
267
265
268

266
269
267
-
1. After the next page appears, from the folder list, select **site** > **wwwroot** > *your-function*. These steps use "FabrikamAzureFunction" as the example function.
270
+
1. After the next page appears, from the folder list, select **site** > **wwwroot** > *your-function*.
271
+
272
+
The following steps use an example function named **FabrikamAzureFunction**.
268
273
269
274

270
275
271
-
1. Open the `function.json` file for editing.
276
+
1. Open the **function.json** file for editing.
272
277
273
278

274
279
275
-
1. In the `bindings` object, check whether the `authLevel` property exists. If the property exists, set the property value to `anonymous`. Otherwise, add that property and set the value.
280
+
1. In the **bindings** object, check whether the **authLevel** property exists. If the property exists, set the property value to **anonymous**. Otherwise, add that property and set the value.
276
281
277
282

278
283
279
284
1. When you're done, save your settings, and then continue to the next section.
280
285
281
286
<aname="set-azure-ad-authentication"></a>
282
287
283
-
###Set up Azure AD authentication for your function app
288
+
## Set up Azure AD authentication for your function app
284
289
285
-
Before you start this task, find and put these values aside for later use:
290
+
Before you start this task, find and save the following values aside for later use. The following sections show how to find these values.
286
291
287
-
* The object (principal) ID that's generated for the system-assigned identity that represents your logic app resource
292
+
* The object (principal) ID for your logic app's managed identity
293
+
* The tenant ID for your Azure Active Directory (Azure AD)
294
+
* Client secret (optional)
295
+
* The application ID URI (resource ID) for your function app
288
296
289
-
* To get this object ID, [enable your logic app's system-assigned identity](create-managed-service-identity.md#azure-portal-system-logic-app).
297
+
### Find the object ID for your logic app's managed identity
290
298
291
-
* Otherwise, to find this object ID, open your logic app in the designer. On your logic app resource menu, under **Settings**, select **Identity** > **System assigned**.
299
+
If your logic app doesn't have a managed identity set up yet, [enable the managed identity for your logic app](create-managed-service-identity.md). Based on the whether you have a Consumption or Standard logic app resource, follow the respective steps:
292
300
293
-
* The tenant ID for your Azure Active Directory (Azure AD)
301
+
#### [Consumption](#tab/consumption)
302
+
303
+
1. After your logic app has its managed identity enabled, on the logic app menu, under **Settings**, select **Identity**, and then select either **System assigned** or **User assigned**.
304
+
305
+
***System assigned**
306
+
307
+
For the system-assigned identity, copy the identity's object ID, for example:
308
+
309
+

310
+
311
+
***User assigned**
312
+
313
+
1. For the user-assigned identity, select the identity to find the object ID, for example:
314
+
315
+

316
+
317
+
1. On the managed identity's **Overview** pane, you can find the identity's object ID, for example:
318
+
319
+

320
+
321
+
#### [Standard](#tab/standard)
322
+
323
+
---
324
+
325
+
### Find the tenant ID for your Azure AD
294
326
295
-
To get your tenant ID, you can run the [`Get-AzureAccount`](/powershell/module/servicemanagement/azure.service/get-azureaccount) PowerShell command. Or, in the Azure portal, follow these steps:
327
+
1. For your Azure Active Directory (Azure AD), find the tenant ID. You can either run the PowerShell command named [**Get-AzureAccount**](/powershell/module/servicemanagement/azure.service/get-azureaccount), or in the Azure portal, follow these steps:
296
328
297
-
1. In the [Azure portal](https://portal.azure.com), open your Azure AD tenant. These steps use "Fabrikam" as the example tenant.
329
+
1. In the [Azure portal](https://portal.azure.com), open your Azure AD tenant. These steps use "Fabrikam" as the example tenant.
298
330
299
-
1. On the tenant menu, under **Manage**, select **Properties**.
331
+
1. On the tenant menu, under **Manage**, select **Properties**.
300
332
301
-
1. Copy your tenant ID, for example, and save that ID for later use.
333
+
1. Copy your tenant ID, for example, and save that ID for later use.
302
334
303
-

335
+

304
336
305
-
* The application ID URI (resource ID) for the target resource that you want to access
337
+
1. For the target resource that you want to access, which is your function app in this case, find the application ID URI (resource ID).
306
338
307
339
* To find these resource IDs, review the [Azure services that support Azure AD](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md#azure-services-that-support-azure-ad-authentication).
308
340
@@ -345,8 +377,8 @@ Now you're ready to set up Azure AD authentication for your function app by crea
345
377
346
378
When you're done, the **Authentication** page now lists the identity provider. From here, you can edit or delete this provider configuration. You're now ready to use the Microsoft identity platform for authentication in your function app.
347
379
348
-
1. Return to the designer and follow the [steps to authenticate access with the managed identity](../logic-apps/create-managed-service-identity.md#authenticate-access-with-identity).
380
+
1. Return to the designer and follow the [steps to authenticate access with the managed identity](create-managed-service-identity.md#authenticate-access-with-identity).
349
381
350
382
## Next steps
351
383
352
-
* Learn about [Logic Apps connectors](../connectors/apis-list.md)
384
+
* Learn about [connectors in Azure Logic Apps](../connectors/apis-list.md)
0 commit comments