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:
- 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.
- 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.
- 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
- 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.
- 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.
- Workaround Using Azure Portal
If CLI continues to fail, attempt creating the Cosmos DB custom endpoint via the Azure Portal:
- Navigate to your IoT Hub in the Azure Portal.
- Select Message Routing > Custom Endpoints.
- Click + Add Endpoint and select Cosmos DB Container.
- Provide the required details:
- Connection string
- Database name (
mydatabase
)- Container name (
notification
)
- Container name (
- Database name (
- Connection string
- 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.