ARM Template To Create Azure IoT Hub with File Upload Support

In this article we will learn how to create azure IoT hub with file upload support. The azure IoT hub supports the file upload feature to maintain the files related to the IoT devices which can be used to store the package files to upgrade the device or any files which are required for certain requirement related to the IoT devices.

Template.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "keyVaultUri": {
      "type": "string"
    },
    "appInsightsKey": {
      "type": "string"
    },
    "serviceName": {
      "type": "string",
      "defaultValue": "SmartDevicesIoTHub"
    },
    "region": {
      "type": "string",
      "defaultValue": "West Europe"
    },
    "location": {
      "type": "string",
      "defaultValue": "eastus"
    },
    "containerName": {
      "type": "string",
      "defaultValue": "AzureblobStorageContainerName"
    },
    "iotHubAccessPolicies": {
      "type": "object"
    }
  },
    "resourceGroup": "[('YourAzureResourceGroupName')]",
    "AzureStorageAccountName": "[concat('YourStorageAccountName',toLower(parameters('location')))]",
    "storageAccountApiVersion": "2018-07-01",
    "iotHubName": "[(parameters('serviceName'))]",
    "iothubApiVersion": "2018-04-01",
    "eventHubDefaultRetentionInDays": 7
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('AzureStorageAccountName')]",
      "location": "[parameters('region')]",
      "apiVersion": "[variables('storageAccountApiVersion')]",
      "sku": {
        "name": "Standard_LRS",
        "tier": "Standard"
      },
      "kind": "StorageV2",
      "properties": {
        "accessTier": "Hot"

      },
      "resources": [
        {
          "name": "[concat('default/', parameters('containerName'))]",
          "type": "blobServices/containers",
          "apiVersion": "2018-07-01",
          "dependsOn": [
            "[variables('AzureStorageAccountName')]"
          ]
        }
      ]
    },
    {
      "name": "[variables('iotHubName')]",
      "type": "Microsoft.Devices/IotHubs",
      "apiVersion": "[variables('iothubApiVersion')]",
      "location": "[parameters('region')]",
      "tags": "[variables('tags')]",
      "sku": {
        "name": "S1",
        "tier": "Standard",
        "capacity": 1
      },
      "dependsOn": [
        "[variables('AzureStorageAccountName')]"
      ],
      "properties": {
        "enableFileUploadNotifications": true,
        "authorizationPolicies": [
          {
            "keyName": "[parameters('iotHubAccessPolicies').iotHubOwner.name]",
            "rights": "[parameters('iotHubAccessPolicies').iotHubOwner.rights]",
            "primaryKey": "[parameters('iotHubAccessPolicies').iotHubOwner.primaryKey]",
            "secondaryKey": "[parameters('iotHubAccessPolicies').iotHubOwner.secondaryKey]"
          }
        ],
        "eventHubEndpoints": {
          "events": {
            "retentionTimeInDays": "[variables('eventHubDefaultRetentionInDays')]",
            "partitionCount": 4,
            "path": "[variables('iotHubName')]"
          },
          "operationsMonitoringEvents": {
            "retentionTimeInDays": "[variables('eventHubDefaultRetentionInDays')]",
            "partitionCount": 4
          }
        },
        "storageEndpoints": {
          "$default": {
            "containerName": "[parameters('containerName')]",
            "connectionString": "[Concat('DefaultEndpointsProtocol=https;AccountName=',variables('AzureStorageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('AzureStorageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]",
            "sasTtlAsIso8601": "PT1H"
          }
        },
        "messagingEndpoints": {
          "fileNotifications": {
            "lockDurationAsIso8601": "PT1M",
            "ttlAsIso8601": "P1D",
            "maxDeliveryCount": 10
          }
        }
      }
    }
  ]
}

Note

The preceding is the just template and you need to replace and modify the template as per your environment details. The following things need to be replaced
  • Resource group Name
  • Azure IoT Hub Name
  • Azure Storage Container Name 
  • Azure Storage Account Name
You can run the preceding template with the help of PowerShell.

Summary

I hope from the preceding article you have learned how to create the IoT hub with file upload support using ARM template.

Related Articles

Post a Comment

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode