How do you set up a Cosmos DB custom endpoint in IoT Hubs?

Meghan Clark 10 Reputation points
2023-02-25T17:04:15.59+00:00

Saving messages from the IoT Hub directly into Cosmos DB via a custom endpoint is a new feature currently in preview. I'm following the official instructions located here: https://learn.microsoft.com/en-us/azure/iot-hub/how-to-routing-portal?tabs=cosmosdb

I'm using the Azure portal to set up the custom endpoint. When I go to the IoT Hub page to set up the custom Cosmos DB endpoint, under "Choose an Existing Cosmos DB Account" I can select my Cosmos DB for Mongo API instance from the dropdown menu, but then in the database dropdown it says "No available items." I have created a database and collection in that account that I can see in the data explorer. Why isn't the database showing up as an option for the custom endpoint? Is there a permissions issue?

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,124 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,447 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Rahul Randive 8,521 Reputation points Microsoft Employee
    2023-02-26T00:19:55.32+00:00

    Thanks for your question.

    As far as permission is concerned, make sure that you have the permissions to access the Cosmos DB account and that your firewall settings allow traffic from the IoT Hub. You can configure firewall settings in the Azure portal under "Networking" in the Cosmos DB account settings.

    https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-configure-firewall#configure-ip-policy

    If the problem persists, please kindly share screenshot.

    Also, please have a look at this techcommunity blog.

    https://techcommunity.microsoft.com/t5/internet-of-things-blog/set-up-an-azure-cosmos-db-custom-endpoint-directly-from-iot-hub/ba-p/3675886

    As per the blog, setting up an Azure Cosmos DB endpoint is pretty straightforward. In the Azure portal, open the IoT Hub blade that you have setup and navigate to the Hub settings. Select "Message Routing" on the left pane and click on "Custom endpoints" and choose "Cosmos DB" from the dropdown list.

    Thank you!

    0 comments No comments

  2. AshokPeddakotla-MSFT 27,491 Reputation points
    2023-03-01T14:25:21.3966667+00:00

    Meghan Clark

    Did you get a chance to see the response from Rahul? In addition to the troubleshooting steps suggested, please see below.

    When I go to the IoT Hub page to set up the custom Cosmos DB endpoint, under "Choose an Existing Cosmos DB Account" I can select my Cosmos DB for Mongo API instance from the dropdown menu, but then in the database dropdown it says "No available items."

    Looks like you are not getting the below fields while adding a route.

    User's image

    Can you confirm if you have added the Database and collections to Your Cosmos DB? Both the resources in same subscription or different subscription?

    If the endpoint resource is in a different subscription than your IoT hub, you need to configure your IoT hub as a trusted Microsoft service before creating a custom endpoint. When you do create the custom endpoint, set the Authentication type to user-assigned identity.

    For more information, see Egress connectivity from IoT Hub to other Azure resources.

    If they are in same subscription and region, try refreshing the database dropdown by clicking the refresh button to see if it resolves the issue.

    You can specify the partition key property name in Partition key name. The partition key property name is defined at the container level and can't be changed once it has been set.

    If you're using the system assigned managed identity for authenticating to Cosmos DB, you must use Azure CLI or Azure PowerShell to assign the Cosmos DB Built-in Data Contributor built-in role definition to the identity. Role assignment for Cosmos DB isn't currently supported from the Azure portal. For more information about the various roles, see Configure role-based access for Azure Cosmos DB. To understand assigning roles via CLI, see Manage Azure Cosmos DB SQL role resources.

    If you need further help in this matter, please comment in the below section and we are happy to discuss!


    If this answers your query, do click Accept Answer and Yes for this answer as helpful. And, if you have any further query do let us know by commenting in the below section.

    0 comments No comments