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
title: Use identity-based connections with Azure Functions triggers and bindings
3
+
description: Learn how to use identity-based connections instead of secrets when connecting to a Service Bus queue using Azure Functions.
3
4
ms.service: azure-functions
4
-
description: Learn how to use identity-based connections instead of connection strings when connecting to a Service Bus queue using Azure Functions.
5
5
ms.topic: tutorial
6
-
ms.date: 10/20/2021
6
+
ms.date: 06/27/2024
7
7
ms.devlang: csharp
8
-
#Customer intent: As a function developer, I want to learn how to use managed identities so that I can avoid having to handle connection strings in my application settings.
8
+
9
+
#Customer intent: As a function developer, I want to learn how to use managed identities so that I can avoid needing to handle secrets or connection strings in my application settings.
9
10
---
10
11
11
12
# Tutorial: Use identity-based connections instead of secrets with triggers and bindings
12
13
13
-
This tutorial shows you how to configure Azure Functions to connect to Azure Service Bus queues using managed identities instead of secrets stored in the function app settings. The tutorial is a continuation of the [Create a function app without default storage secrets in its definition][previous tutorial] tutorial. To learn more about identity-based connections, see [Configure an identity-based connection.](functions-reference.md#configure-an-identity-based-connection).
14
+
This tutorial shows you how to configure Azure Functions to connect to Azure Service Bus queues by using managed identities, instead of secrets stored in the function app settings. The tutorial is a continuation of the [Create a function app without default storage secrets in its definition][previous tutorial] tutorial. To learn more about identity-based connections, see [Configure an identity-based connection.](functions-reference.md#configure-an-identity-based-connection).
14
15
15
-
While the procedures shown work generally for all languages, this tutorial currently supports C# class library functions on Windows specifically.
16
+
While the procedures shown work generally for all languages, this tutorial currently supports C# class library functions on Windows specifically.
16
17
17
-
In this tutorial, you'll learn how to:
18
+
In this tutorial, you learn how to:
18
19
19
20
> [!div class="checklist"]
20
21
>
21
-
> * Create a Service Bus namespace and queue.
22
-
> * Configure your function app with managed identity
23
-
> * Create a role assignment granting that identity permission to read from the Service Bus queue
24
-
> * Create and deploy a function app with a Service Bus trigger.
25
-
> * Verify your identity-based connection to Service Bus
22
+
> - Create a Service Bus namespace and queue.
23
+
> - Configure your function app with a managed identity.
24
+
> - Create a role assignment granting that identity permission to read from the Service Bus queue.
25
+
> - Create and deploy a function app with a Service Bus trigger.
26
+
> - Verify your identity-based connection to the Service Bus.
26
27
27
28
## Prerequisite
28
29
29
30
Complete the previous tutorial: [Create a function app with identity-based connections][previous tutorial].
30
31
31
-
## Create a service bus and queue
32
+
## Create a Service Bus namespace and queue
32
33
33
34
1. In the [Azure portal](https://portal.azure.com), choose **Create a resource (+)**.
34
35
35
-
1. On the **Create a resource** page, select **Integration** > **Service Bus**.
36
+
1. On the **Create a resource** page, search for and select **Service Bus**, and then select **Create**.
36
37
37
38
1. On the **Basics** page, use the following table to configure the Service Bus namespace settings. Use the default values for the remaining options.
38
39
@@ -50,61 +51,59 @@ Complete the previous tutorial: [Create a function app with identity-based conne
50
51
51
52
1. In your new Service Bus namespace, select **+ Queue** to add a queue.
52
53
53
-
1.Type `myinputqueue` as the new queue's name and select **Create**.
54
+
1.Enter **myinputqueue** as the new queue's name and select **Create**.
54
55
55
-
Now, that you have a queue, you will add a role assignment to the managed identity of your function app.
56
+
Now that you have a queue, you can add a role assignment to the managed identity of your function app.
56
57
57
58
## Configure your Service Bus trigger with a managed identity
58
59
59
-
To use Service Bus triggers with identity-based connections, you will need to add the **Azure Service Bus Data Receiver** role assignment to the managed identity in your function app. This role is required when using managed identities to trigger off of your service bus namespace. You can also add your own account to this role, which makes it possible to connect to the service bus namespace during local testing.
60
+
To use Service Bus triggers with identity-based connections, you need to add the **Azure Service Bus Data Receiver** role assignment to the managed identity in your function app. This role is required when using managed identities to trigger off of your Service Bus namespace. You can also add your own account to this role, which makes it possible to connect to the Service Bus namespace during local testing.
60
61
61
62
> [!NOTE]
62
-
> Role requirements for using identity-based connections vary depending on the service and how you are connecting to it. Needs vary across triggers, input bindings, and output bindings. For more details on specific role requirements, please refer to the trigger and binding documentation for the service.
63
+
> Role requirements for using identity-based connections vary depending on the service and how you are connecting to it. Needs vary across triggers, input bindings, and output bindings. For more information about specific role requirements, see the trigger and binding documentation for the service.
63
64
64
-
1. In your service bus namespace that you just created, select **Access Control (IAM)**. This is where you can view and configure who has access to the resource.
65
+
1. In your Service Bus namespace that you created, select **Access control (IAM)**. This page is where you can view and configure who has access to the resource.
65
66
66
-
1.Click**Add** and select **add role assignment**.
67
+
1.Select**+ Add** and select **Add role assignment**.
67
68
68
-
1. Search for **Azure Service Bus Data Receiver**, select it, and click**Next**.
69
+
1. Search for **Azure Service Bus Data Receiver**, select it, and then select**Next**.
69
70
70
71
1. On the **Members** tab, under **Assign access to**, choose **Managed Identity**
71
72
72
-
1.Click**Select members** to open the **Select managed identities** panel.
73
+
1.Select**Select members** to open the **Select managed identities** panel.
73
74
74
75
1. Confirm that the **Subscription** is the one in which you created the resources earlier.
75
76
76
-
1. In the **Managed identity** selector, choose **Function App** from the **System-assigned managed identity** category. The label "Function App" may have a number in parentheses next to it, indicating the number of apps in the subscription with system-assigned identities.
77
+
1. In the **Managed identity** selector, choose **Function App** from the **System-assigned managed identity** category. The **Function App** label might have a number in parentheses next to it, indicating the number of apps in the subscription with system-assigned identities.
77
78
78
79
1. Your app should appear in a list below the input fields. If you don't see it, you can use the **Select** box to filter the results with your app's name.
79
80
80
-
1.Click on your application. It should move down into the **Selected members** section. Click**Select**.
81
+
1.Select your application. It should move down into the **Selected members** section. Select**Select**.
81
82
82
-
1. Back on the **Add role assignment** screen, click**Review + assign**. Review the configuration, and then click**Review + assign**.
83
+
1. Back on the **Add role assignment** screen, select**Review + assign**. Review the configuration, and then select**Review + assign**.
83
84
84
-
You've granted your function app access to the service bus namespace using managed identities.
85
+
You've granted your function app access to the Service Bus namespace using managed identities.
85
86
86
-
## Connect to Service Bus in your function app
87
+
## Connect to the Service Bus in your function app
87
88
88
89
1. In the portal, search for the function app you created in the [previous tutorial], or browse to it in the **Function App** page.
89
90
90
-
1. In your function app, select**Configuration** under **Settings**.
91
+
1. In your function app, expand**Settings**, and then select **Environment variables**.
91
92
92
-
1. In **Application settings**, select **+ New application setting** to create the new settingin the following table.
93
+
1. In the **App settings** tab, select **+ Add** to create a setting. Use the information in the following table to enter the **Name** and **Value** for the new setting:
93
94
94
95
| Name | Value | Description |
95
96
| ------------ | ---------------- | ----------- |
96
97
|**ServiceBusConnection__fullyQualifiedNamespace**| <SERVICE_BUS_NAMESPACE>.servicebus.windows.net | This setting connects your function app to the Service Bus using an identity-based connection instead of secrets. |
97
98
98
-
1.After you create the two settings, select **Save**>**Confirm**.
99
+
1.Select **Apply**, and then select **Apply**and**Confirm** to save your changes and restart the app function.
99
100
100
101
> [!NOTE]
101
-
> When using [Azure App Configuration](../../articles/azure-app-configuration/quickstart-azure-functions-csharp.md) or [Key Vault](../key-vault/general/overview.md) to provide settings for Managed Identity connections, setting names should use a valid key separator such as `:` or `/` in place of the `__` to ensure names are resolved correctly.
102
-
>
102
+
> When you use [Azure App Configuration](../../articles/azure-app-configuration/quickstart-azure-functions-csharp.md) or [Key Vault](../key-vault/general/overview.md) to provide settings for Managed Identity connections, setting names should use a valid key separator, such as `:` or `/`, in place of the `__` to ensure names are resolved correctly.
103
+
>
103
104
> For example, `ServiceBusConnection:fullyQualifiedNamespace`.
104
105
105
-
Now that you've prepared the function app to connect to the service bus namespace using a managed identity, you can add a new function that uses a Service Bus trigger to your local project.
106
-
107
-
106
+
Now that you've prepared the function app to connect to the Service Bus namespace using a managed identity, you can add a new function that uses a Service Bus trigger to your local project.
108
107
109
108
## Add a Service Bus triggered function
110
109
@@ -114,29 +113,29 @@ Now that you've prepared the function app to connect to the service bus namespac
Thisaddsthecodefor a new Service Bus trigger and a reference to the extension package. You need to add a service bus namespace connection setting for this trigger.
136
+
Thiscommandaddsthecodefor a new Service Bus trigger and a reference to the extension package. You need to add a Service Bus namespace connection setting for this trigger.
138
137
139
-
1. Open the new ServiceBusTrigger.cs project file and replace the `ServiceBusTrigger` class with the following code:
138
+
1. Open the new *ServiceBusTrigger.cs* project file and replace the `ServiceBusTrigger` class with the following code:
140
139
141
140
```csharp
142
141
public static class ServiceBusTrigger
@@ -150,14 +149,14 @@ Now that you've prepared the function app to connect to the service bus namespac
0 commit comments