Skip to content

Commit d37f93c

Browse files
Merge pull request #278617 from dksimpson/tsk261306-dks-4
Refresh article: Use identity-based connections with Azure Functions triggers and bindings [Task 261306]
2 parents d3d66a5 + 622b560 commit d37f93c

File tree

2 files changed

+118
-123
lines changed

2 files changed

+118
-123
lines changed
Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
---
22
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.
34
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.
55
ms.topic: tutorial
6-
ms.date: 10/20/2021
6+
ms.date: 06/27/2024
77
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.
910
---
1011

1112
# Tutorial: Use identity-based connections instead of secrets with triggers and bindings
1213

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).
1415

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.
1617

17-
In this tutorial, you'll learn how to:
18+
In this tutorial, you learn how to:
1819

1920
> [!div class="checklist"]
2021
>
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.
2627
2728
## Prerequisite
2829

2930
Complete the previous tutorial: [Create a function app with identity-based connections][previous tutorial].
3031

31-
## Create a service bus and queue
32+
## Create a Service Bus namespace and queue
3233

3334
1. In the [Azure portal](https://portal.azure.com), choose **Create a resource (+)**.
3435

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**.
3637

3738
1. On the **Basics** page, use the following table to configure the Service Bus namespace settings. Use the default values for the remaining options.
3839

@@ -50,61 +51,59 @@ Complete the previous tutorial: [Create a function app with identity-based conne
5051

5152
1. In your new Service Bus namespace, select **+ Queue** to add a queue.
5253

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**.
5455

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.
5657

5758
## Configure your Service Bus trigger with a managed identity
5859

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.
6061

6162
> [!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.
6364
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.
6566

66-
1. Click **Add** and select **add role assignment**.
67+
1. Select **+ Add** and select **Add role assignment**.
6768

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**.
6970

7071
1. On the **Members** tab, under **Assign access to**, choose **Managed Identity**
7172

72-
1. Click **Select members** to open the **Select managed identities** panel.
73+
1. Select **Select members** to open the **Select managed identities** panel.
7374

7475
1. Confirm that the **Subscription** is the one in which you created the resources earlier.
7576

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.
7778

7879
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.
7980

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**.
8182

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**.
8384

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.
8586

86-
## Connect to Service Bus in your function app
87+
## Connect to the Service Bus in your function app
8788

8889
1. In the portal, search for the function app you created in the [previous tutorial], or browse to it in the **Function App** page.
8990

90-
1. In your function app, select **Configuration** under **Settings**.
91+
1. In your function app, expand **Settings**, and then select **Environment variables**.
9192

92-
1. In **Application settings**, select **+ New application setting** to create the new setting in 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:
9394

9495
| Name | Value | Description |
9596
| ------------ | ---------------- | ----------- |
9697
| **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. |
9798

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.
99100

100101
> [!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+
>
103104
> For example, `ServiceBusConnection:fullyQualifiedNamespace`.
104105
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.
108107

109108
## Add a Service Bus triggered function
110109

@@ -114,29 +113,29 @@ Now that you've prepared the function app to connect to the service bus namespac
114113
func init LocalFunctionProj --dotnet
115114
```
116115

117-
1. Navigate into the project folder:
116+
1. Navigate to the project folder:
118117

119118
```console
120119
cd LocalFunctionProj
121120
```
122121

123-
1. In the root project folder, run the following commands:
122+
1. In the root project folder, run the following command:
124123

125124
```command
126125
dotnet add package Microsoft.Azure.WebJobs.Extensions.ServiceBus --version 5.2.0
127126
```
128127

129-
This replaces the default version of the Service Bus extension package with a version that supports managed identities.
128+
This command replaces the default version of the Service Bus extension package with a version that supports managed identities.
130129

131130
1. Run the following command to add a Service Bus triggered function to the project:
132131

133132
```csharp
134133
func new --name ServiceBusTrigger --template ServiceBusQueueTrigger
135134
```
136135

137-
This adds the code for 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+
This command adds the code for 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.
138137

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:
140139

141140
```csharp
142141
public static class ServiceBusTrigger
@@ -150,14 +149,14 @@ Now that you've prepared the function app to connect to the service bus namespac
150149
}
151150
```
152151

153-
This code sample updates the queue name to `myinputqueue`, which is the same name as you queue you created earlier. It also sets the name of the Service Bus connection to `ServiceBusConnection`. This is the Service Bus namespace used by the identity-based connection `ServiceBusConnection__fullyQualifiedNamespace` you configured in the portal.
152+
This code sample updates the queue name to `myinputqueue`, which is the same name as you queue you created earlier. It also sets the name of the Service Bus connection to `ServiceBusConnection`. This name is the Service Bus namespace used by the identity-based connection `ServiceBusConnection__fullyQualifiedNamespace` you configured in the portal.
154153

155154
> [!NOTE]
156-
> If you try to run your functions now using `func start` you'll receive an error. This is because you don't have an identity-based connection defined locally. If you want to run your function locally, set the app setting `ServiceBusConnection__fullyQualifiedNamespace` in `local.settings.json` as you did in [the previous section](#connect-to-service-bus-in-your-function-app). In addition, you'll need to assign the role to your developer identity. For more details, please refer to the [local development with identity-based connections documentation](./functions-reference.md#local-development-with-identity-based-connections).
155+
> If you try to run your functions now using `func start`, you'll receive an error. This is because you don't have an identity-based connection defined locally. If you want to run your function locally, set the app setting `ServiceBusConnection__fullyQualifiedNamespace` in `local.settings.json` as you did in [the previous section](#connect-to-the service-bus-in-your-function-app). In addition, you need to assign the role to your developer identity. For more information, see [local development with identity-based connections](./functions-reference.md#local-development-with-identity-based-connections).
157156

158157
> [!NOTE]
159158
> 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.
160-
>
159+
>
161160
> For example, `ServiceBusConnection:fullyQualifiedNamespace`.
162161

163162
## Publish the updated project
@@ -176,7 +175,7 @@ Now that you've prepared the function app to connect to the service bus namespac
176175
az functionapp deploy -n FUNCTION_APP_NAME -g RESOURCE_GROUP_NAME --src-path PATH_TO_ZIP
177176
```
178177

179-
Now that you have updated the function app with the new trigger, you can verify that it works using the identity.
178+
Now that you've updated the function app with the new trigger, you can verify that it works using the identity.
180179

181180
## Validate your changes
182181

@@ -186,28 +185,26 @@ Now that you have updated the function app with the new trigger, you can verify
186185

187186
1. In your instance, select **Live Metrics** under **Investigate**.
188187

189-
1. Keep the previous tab open, and open the Azure portal in a new tab. In your new tab, navigate to your Service Bus namespace, select **Queues** from the left blade.
188+
1. Keep the previous tab open, and open the Azure portal in a new tab. In your new tab, navigate to your Service Bus namespace, select **Queues** from the left menu.
190189

191190
1. Select your queue named `myinputqueue`.
192191

193-
1. Select **Service Bus Explorer** from the left blade.
192+
1. Select **Service Bus Explorer** from the left menu.
194193

195194
1. Send a test message.
196195

197196
1. Select your open **Live Metrics** tab and see the Service Bus queue execution.
198197

199-
Congratulations! You have successfully set up your Service Bus queue trigger with a managed identity!
198+
Congratulations! You have successfully set up your Service Bus queue trigger with a managed identity.
200199

201200
[!INCLUDE [clean-up-section-portal](../../includes/clean-up-section-portal.md)]
202201

203202
## Next steps
204203

205204
In this tutorial, you created a function app with identity-based connections.
206205

207-
Use the following links to learn more Azure Functions with identity-based connections:
208-
209-
- [Managed identity in Azure Functions](../app-service/overview-managed-identity.md)
210-
- [Identity-based connections in Azure Functions](./functions-reference.md#configure-an-identity-based-connection)
211-
- [Functions documentation for local development](./functions-reference.md#local-development-with-identity-based-connections)
206+
Advance to the next article to learn how to manage identity.
207+
> [!div class="nextstepaction"]
208+
> [Managed identity in Azure Functions](../app-service/overview-managed-identity.md)
212209

213210
[previous tutorial]: ./functions-identity-based-connections-tutorial.md

0 commit comments

Comments
 (0)