使用 Azure Resource Manager 範本建立 IoT 中樞 (PowerShell)
本文顯示如何使用 Azure Resource Manager 範本,以使用 Azure PowerShell 來建立 IoT 中樞和取用者群組。 Resource Manager 範本是 JSON 檔案,該檔案定義您需要為您的解決方案部署的資源。 如需開發 Resource Manager 範本的詳細資訊,請參閱 Azure Resource Manager 文件。
必要條件
Azure PowerShell 模組或 Azure Cloud Shell
如果您不想要在本機安裝 PowerShell 模組,則 Azure Cloud Shell 十分有用,因為 Cloud Shell 會從瀏覽器執行。
建立 IoT 中樞
本文中使用的 Resource Manager JSON 範本是 Azure 快速入門範本中許多範本的其中一個。 此 JSON 範本會建立具有三個端點的 Azure IoT 中樞 (Eventhub、雲端到裝置和傳訊) 以及取用者群組。 如需 IoT 中樞範本結構描述的詳細資訊,請參閱 Microsoft.Devices (IoT 中樞) 資源類型。
使用下列 PowerShell 命令來建立資源群組,然後使用該資源群組來建立 IoT 中樞。 JSON 範本用於 -TemplateUri
中。
若要執行下列 PowerShell 指令碼,請選取 [試試看] 開啟 Azure Cloud Shell。 複製指令碼,並將其貼入您的殼層,然後按 Enter 鍵。 答覆提示。 這些提示將協助您建立新的資源、選擇區域,以及建立新的 IoT 中樞。 回答之後,IoT 中樞的確認就會列印至主控台。
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
$location = Read-Host -Prompt "Enter the location (for example: centralus)"
$iotHubName = Read-Host -Prompt "Enter the IoT Hub name"
New-AzResourceGroup -Name $resourceGroupName -Location "$location"
New-AzResourceGroupDeployment `
-ResourceGroupName $resourceGroupName `
-TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.devices/iothub-with-consumergroup-create/azuredeploy.json" `
-iotHubName $iotHubName
注意
若要使用您自己的範本,請先上傳範本檔案至 Cloud Shell,然後使用 -TemplateFile
切換為指定檔案名稱。 如需範例,請參閱部署範本。
後續步驟
鑑於您已使用 Azure Resource Manager 範本部署 IoT 中樞,建議探索以下資源:
- IoT 中樞資源提供者 REST API 的功能
- Azure Resource Manager 的功能
- 在 Microsoft.Devices 資源類型 範本中使用的 JSON 語法和屬性
若要深入了解如何開發 IoT 中樞,請參閱 Azure IoT SDK。
若要進一步探索 IoT 中樞的功能,請參閱︰