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/api-management/api-management-howto-log-event-hubs.md
+83-71Lines changed: 83 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ author: dlepow
6
6
7
7
ms.service: azure-api-management
8
8
ms.topic: how-to
9
-
ms.date: 07/12/2024
9
+
ms.date: 09/04/2024
10
10
ms.author: danlep
11
11
12
12
---
@@ -31,64 +31,77 @@ Azure Event Hubs is a highly scalable data ingress service that can ingest milli
31
31
32
32
To log events to the event hub, you need to configure credentials for access from API Management. API Management supports either of the two following access mechanisms:
33
33
34
+
* A managed identity for your API Management instance (recommended)
34
35
* An Event Hubs connection string
35
-
* A managed identity for your API Management instance.
To create an Event Hubs connection string, see [Get an Event Hubs connection string](../event-hubs/event-hubs-get-connection-string.md).
40
-
41
-
* You can use a connection string for the Event Hubs namespace or for the specific event hub you use for logging from API Management.
42
-
* The shared access policy for the connection string must enable at least **Send** permissions.
37
+
> [!NOTE]
38
+
> Where possible, Microsoft recommends using managed identity credentials for enhanced security.
43
39
44
-
### Option 2: Configure API Management managed identity
45
40
46
-
> [!NOTE]
47
-
> Using an API Management managed identity for logging events to an event hub is supported in API Management REST API version `2022-04-01-preview` or later.
41
+
### Option 1: Configure API Management managed identity
48
42
49
43
1. Enable a system-assigned or user-assigned [managed identity for API Management](api-management-howto-use-managed-service-identity.md) in your API Management instance.
50
44
51
45
* If you enable a user-assigned managed identity, take note of the identity's **Client ID**.
52
46
53
47
1. Assign the identity the **Azure Event Hubs Data sender** role, scoped to the Event Hubs namespace or to the event hub used for logging. To assign the role, use the [Azure portal](../role-based-access-control/role-assignments-portal.yml) or other Azure tools.
To create an Event Hubs connection string, see [Get an Event Hubs connection string](../event-hubs/event-hubs-get-connection-string.md).
53
+
54
+
* You can use a connection string for the Event Hubs namespace or for the specific event hub you use for logging from API Management.
55
+
* The shared access policy for the connection string must enable at least **Send** permissions.
56
+
57
+
55
58
## Create an API Management logger
56
59
The next step is to configure a [logger](/rest/api/apimanagement/current-ga/logger) in your API Management service so that it can log events to the event hub.
57
60
58
61
Create and manage API Management loggers by using the [API Management REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) directly or by using tools including [Azure PowerShell](/powershell/module/az.apimanagement/new-azapimanagementlogger), a Bicep template, or an Azure Resource Management template.
59
62
60
-
### Logger with connection string credentials
63
+
### Option 1: Logger with managed identity credentials (recommended)
61
64
62
-
For prerequisites, see [Configure Event Hubs connection string](#option-1-configure-event-hubs-connection-string).
65
+
You can configure an API Management logger to an event hub using either system-assigned or user-assigned managed identity credentials.
63
66
64
-
#### [PowerShell](#tab/PowerShell)
67
+
###Logger with system-assigned managed identity credentials
65
68
66
-
The following example uses the [New-AzApiManagementLogger](/powershell/module/az.apimanagement/new-azapimanagementlogger) cmdlet to create a logger to an event hub by configuring a connection string.
69
+
For prerequisites, see [Configure API Management managed identity](#option-1-configure-api-management-managed-identity).
67
70
68
-
```powershell
69
-
# API Management service-specific details
70
-
$apimServiceName = "apim-hello-world"
71
-
$resourceGroupName = "myResourceGroup"
71
+
#### [REST API](#tab/PowerShell)
72
+
73
+
Use the API Management [Logger - Create or Update](/rest/api/apimanagement/current-preview/logger/create-or-update) REST API with the following request body.
74
+
75
+
```JSON
76
+
{
77
+
"properties": {
78
+
"loggerType": "azureEventHub",
79
+
"description": "Event Hub logger with system-assigned managed identity",
#### Logger with user-assigned managed identity credentials
118
133
119
-
### Logger with system-assigned managed identity credentials
120
-
121
-
For prerequisites, see [Configure API Management managed identity](#option-2-configure-api-management-managed-identity).
134
+
For prerequisites, see [Configure API Management managed identity](#option-1-configure-api-management-managed-identity).
122
135
123
136
#### [REST API](#tab/PowerShell)
124
137
125
-
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) or a Bicep or ARM template to configure a logger to an event hub with system-assigned managed identity credentials.
138
+
Use the API Management [Logger - Create or Update](/rest/api/apimanagement/current-preview/logger/create-or-update) REST API with the following request body.
139
+
126
140
127
141
```JSON
128
142
{
129
143
"properties": {
130
144
"loggerType": "azureEventHub",
131
-
"description": "adding a new logger with system assigned managed identity",
145
+
"description": "Event Hub logger with user-assigned managed identity",
### Logger with user-assigned managed identity credentials
185
198
186
-
For prerequisites, see [Configure API Management managed identity](#option-2-configure-api-management-managed-identity).
187
199
188
-
#### [REST API](#tab/PowerShell)
200
+
###Option 2. Logger with connection string credentials
189
201
190
-
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) or a Bicep or ARM template to configure a logger to an event hub with user-assigned managed identity credentials.
202
+
For prerequisites, see [Configure Event Hubs connection string](#option-2-configure-event-hubs-connection-string).
191
203
192
-
```JSON
193
-
{
194
-
"properties": {
195
-
"loggerType": "azureEventHub",
196
-
"description": "adding a new logger with user-assigned managed identity",
> Where possible, Microsoft recommends configuring the logger with managed identity credentials. See [Configure logger with managed identity credentials](#option-1-logger-with-managed-identity-credentials-recommended), earlier in this article.
204
206
207
+
#### [PowerShell](#tab/PowerShell)
208
+
209
+
The following example uses the [New-AzApiManagementLogger](/powershell/module/az.apimanagement/new-azapimanagementlogger) cmdlet to create a logger to an event hub by configuring a connection string.
0 commit comments