Quickstart: Create an event hub by using an ARM template

In this quickstart, you create an event hub by using an Azure Resource Manager template (ARM template). You deploy an ARM template to create a namespace of type Event Hubs, with one event hub.

Prerequisites

Review the template

The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.4.1318.3566",
      "templateHash": "1979185172851008433"
    }
  },
  "parameters": {
    "projectName": {
      "type": "string",
      "metadata": {
        "description": "Specifies a project name that is used to generate the Event Hub name and the Namespace name."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Specifies the Azure location for all resources."
      }
    },
    "eventHubSku": {
      "type": "string",
      "defaultValue": "Standard",
      "allowedValues": [
        "Basic",
        "Standard"
      ],
      "metadata": {
        "description": "Specifies the messaging tier for Event Hub Namespace."
      }
    }
  },
  "variables": {
    "eventHubNamespaceName": "[format('{0}ns', parameters('projectName'))]",
    "eventHubName": "[parameters('projectName')]"
  },
  "resources": [
    {
      "type": "Microsoft.EventHub/namespaces",
      "apiVersion": "2021-11-01",
      "name": "[variables('eventHubNamespaceName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('eventHubSku')]",
        "tier": "[parameters('eventHubSku')]",
        "capacity": 1
      },
      "properties": {
        "isAutoInflateEnabled": false,
        "maximumThroughputUnits": 0
      }
    },
    {
      "type": "Microsoft.EventHub/namespaces/eventhubs",
      "apiVersion": "2021-11-01",
      "name": "[format('{0}/{1}', variables('eventHubNamespaceName'), variables('eventHubName'))]",
      "properties": {
        "messageRetentionInDays": 7,
        "partitionCount": 1
      },
      "dependsOn": [
        "[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]"
      ]
    }
  ]
}

The resources defined in the template include:

To find more template samples, see Azure Quickstart Templates.

Deploy the template

Using Azure portal user interface

  1. If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template opens in the Azure portal.

    Deploy to Azure

  2. Select an existing resource group or create a resource group and select it.

  3. Select the region.

  4. Enter a unique name for the project. This name is used to generate names for an Event Hubs namespace and an event hub in the namespace.

  5. Select Review + create.

  6. On the Review + create page, select Create. To deploy the template:

  1. Follow the instructions to sign in to the Azure power Shell.

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. chinaeast)"
    $resourceGroupName = "${projectName}rg"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.eventhub/eventhubs-create-namespace-and-eventhub/azuredeploy.json"
    
    New-AzResourceGroup -Name $resourceGroupName -Location $location
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -projectName $projectName
    
    Write-Host "Press [ENTER] to continue ..."
    

    It takes a few moments to create an event hub.

  2. Select Copy to copy the PowerShell script.

  3. Right-click the shell console, and then select Paste.

  4. Press ENTER to run the commands.

Validate the deployment

To verify the deployment, you can either open the resource group from the Azure portal, or use the following Azure PowerShell script.

$projectName = Read-Host -Prompt "Enter the same project name that you used in the last procedure"
$resourceGroupName = "${projectName}rg"
$namespaceName = "${projectName}ns"

Get-AzEventHub -ResourceGroupName $resourceGroupName -Namespace $namespaceName

Write-Host "Press [ENTER] to continue ..."

Clean up resources

When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.

$projectName = Read-Host -Prompt "Enter the same project name that you used in the last procedure"
$resourceGroupName = "${projectName}rg"

Remove-AzResourceGroup -ResourceGroupName $resourceGroupName

Write-Host "Press [ENTER] to continue ..."

Next steps

In this article, you created an Event Hubs namespace, and an event hub in the namespace. For step-by-step instructions to send events to (or) receive events from an event hub, see the Send and receive events tutorials: