How to create a Cosmos DB container as a custom endpoint in Azure IoT Hub.

Linganiveth 0 Reputation points
2024-11-21T08:54:24.9833333+00:00

Observed Error:

  • {'code': 500019, 'httpStatusCode': 500, 'message': 'Internal Error. If you contact a support representative please include this correlation identifier: <UUID>, timestamp: <TIME>, errorcode: IH500019.'}

Command group iot hub message-endpoint is in preview and under development.

Environment Details:

  1. IoT Hub: my-IoTHub Region: Central India (primary), South India (secondary). SKU: S1 (Standard).
  2. Cosmos DB: my-db

Region: Central India.

  • Database: mydatabase.

Container: notification.

  1. Both resources are provisioned successfully and in the same resource group (my-rg).

Steps Taken:

Verified IoT Hub and Cosmos DB provisioning and configurations. Ensured the connection string and Cosmos DB container details were correct. Repeated the command multiple times, consistently encountering the error.

Expected Outcome: The custom endpoint for Cosmos DB container should be created successfully in the IoT Hub using CLI commands.

Request: Kindly assist in resolving the internal error or provide guidance for correctly configuring the custom Cosmos DB endpoint in IoT Hub.

  • Commands Tried:

az iot hub message-endpoint create cosmosdb-container \
  --hub-name my-IoTHub \
  --endpoint-name notificationEP \
  --connection-string " " \
  --container-name notification \
  --database-name mydatabase
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,222 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 26,451 Reputation points MVP
    2024-11-23T10:26:11.7+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    The error IH500019 in Azure IoT Hub while attempting to create a Cosmos DB container as a custom endpoint suggests an internal issue, but it could also result from configuration or connectivity problems. Here’s how you can address and debug the issue:

    1. Verify Prerequisites

    a. IoT Hub SKU

    Ensure that your IoT Hub SKU (S1 Standard) supports message routing and custom endpoints. S1 supports message routing to Cosmos DB containers.

    b. Azure CLI Version

    Ensure that the Azure CLI is updated to the latest version:

    bash
    
    az upgrade
    

    Ensure the IoT CLI extension is also up-to-date:

    bash
    
    az extension update --name azure-iot
    

    c. Cosmos DB Write Permissions

    Ensure that the Cosmos DB has write permissions and is accessible from IoT Hub. Confirm the container is created with partition key support, which is required for Cosmos DB custom endpoints.


    1. Validate Connection String

    Check the format of the Cosmos DB connection string used in the command. It should resemble:

    php
    
    AccountEndpoint=https://<COSMOS-DB-ACCOUNT>.documents.azure.com:443/;AccountKey=<PRIMARY-OR-SECONDARY-KEY>;Database=mydatabase;
    

    Retrieve the connection string using the following command:

    bash
    
    az cosmosdb keys list \
      --name my-db \
      --resource-group my-rg \
      --
    

    Replace <PRIMARY-OR-SECONDARY-KEY> with the correct key. Ensure the database name and container name match the Cosmos DB configuration.


    1. Command Syntax

    Re-run the az iot hub message-endpoint create command with correct parameters:

    bash
    
    az iot hub message-endpoint create cosmosdb-container \
      --hub-name my-IoTHub \
      --endpoint-name notificationEP \
      --connection-string 
    
    1. Validate Cross-Region Configuration

    Since your IoT Hub is in Central India (primary) and Cosmos DB is also in Central India, there shouldn't be any cross-region latency or mismatch issues. However, ensure that the firewall for Cosmos DB allows access from IoT Hub.

    To enable IoT Hub's access, ensure the Cosmos DB firewall allows connections from All Azure Services, or explicitly whitelist IoT Hub's IP addresses.


    1. Debugging and Logs

    a. Enable Debug Logging

    Enable detailed logs for the Azure CLI to capture more information:

    bash
    
    az iot hub message-endpoint create cosmosdb-container \
      --hub-name my-IoTHub \
      --endpoint-name notificationEP \
      --connection-string 
    

    Analyze the debug logs for clues.

    b. Check Azure Service Health

    Verify there are no ongoing service outages in the Central India region for IoT Hub or Cosmos DB:

    • Visit the Azure Status page.
    • Check the IoT Hub and Cosmos DB status for the Central India region.

    c. Monitor Resource Logs

    Enable diagnostic settings on IoT Hub and Cosmos DB to capture detailed logs. Check if IoT Hub successfully connects to Cosmos DB.


    1. Workaround Using Azure Portal

    If CLI continues to fail, attempt creating the Cosmos DB custom endpoint via the Azure Portal:

    1. Navigate to your IoT Hub in the Azure Portal.
    2. Select Message Routing > Custom Endpoints.
    3. Click + Add Endpoint and select Cosmos DB Container.
    4. Provide the required details:
      • Connection string
        • Database name (mydatabase)
          • Container name (notification)
    5. Save the endpoint.

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


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.