Attempt to send message from Azure Function to Azure SignalR fails with 403 forbidden

Macháček Martin 211 Reputation points
2024-05-22T07:47:42.9666667+00:00

Hi,

I'm using Azure SignalR in serverless mode. I've an Azure Function which receives events from Event Hub and sends messages to Azure SignalR.

[Function(nameof(EventHubEventsHandler))]
[SignalROutput(HubName = "userevents", ConnectionStringSetting = "SignalRConnectionSetting")]
public async Task<List<SignalRMessageAction>> Run([EventHubTrigger("userschanged", Connection = "EventHubConnectionSetting")] EventData[] events)

{
    var messages = new List<SignalRMessageAction>();
    foreach (EventData @event in events)
    {
        try
        {
           messages.Add(new SignalRMessageAction("userChanged")
           {
               Arguments = new[] { "user changed" },
           });
        }
        catch (Exception ex)
        {
            ...
        }
    }
    return messages;
}

The connection string SignalRConnectionSetting in Azure Function App settings is defined like Endpoint=https://xxx.service.signalr.net;AccessKey=yyy;Version=1.0;

Azure Function is triggered successfully, but in Application Insights I see that the attempt to send message to Azure SignalR fails with 403 forbidden.

What I see in the logs:

GET https://xxx.service.signalr.net/api/v1/auth/accessKey
Result code: 200
POST https://xxx.service.signalr.net/api/hubs/userevents/:send?api-version=2022-06-01
Result code: 403
System.Net.Http.HttpRequestException
Exception while executing function: Functions.EventHubEventsHandler Azure SignalR service runtime error. Request Uri: https://xxx.service.signalr.net/api/hubs/userevents/:send?api-version=2022-06-01 Response status code does not indicate success: 403 (Forbidden) 

I've no clue what can be wrong.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,145 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
147 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.