Skip to content

Commit cb08afc

Browse files
Merge pull request #107741 from dbradish-microsoft/dbradish_2020-03-14_notificationHubs
first pass at new Azure CLI article for notification hubs
2 parents 428c753 + 4c2cd4a commit cb08afc

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

articles/notification-hubs/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
items:
1212
- name: Create a notification hub - Azure portal
1313
href: create-notification-hub-portal.md
14+
- name: Create a notification hub - Azure CLI
15+
href: create-notification-hub-azure-cli.md
1416
- name: Configure a notification hub - Azure portal
1517
href: configure-notification-hub-portal-pns-settings.md
1618
- name: Tutorials
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
title: Quickstart - Create an Azure notification hub using the Azure CLI | Microsoft Docs
3+
description: In this tutorial, you learn how to create an Azure notification hub using the Azure CLI.
4+
services: notification-hubs
5+
author: dbradish-microsoft
6+
manager: barbkess
7+
editor: sethmanheim
8+
9+
ms.service: notification-hubs
10+
ms.devlang: azurecli
11+
ms.workload: mobile
12+
ms.topic: quickstart
13+
ms.date: 03/17/2020
14+
ms.author: dbradish
15+
ms.reviewer: sethm
16+
ms.lastreviewed: 03/18/2020
17+
---
18+
19+
# Quickstart: Create an Azure notification hub using the Azure CLI
20+
21+
Azure Notification Hubs provide an easy-to-use and scaled-out push engine that allows you to send notifications to any platform (iOS, Android, Windows, Kindle, Baidu, etc.) from any backend (cloud or on-premises). For more information about the service, see [What is Azure Notification Hubs?](notification-hubs-push-notification-overview.md).
22+
23+
In this quickstart, you create a notification hub using the Azure CLI. The first section gives you steps to create a notification hub namespace, and query access policy information for that namespace. The second section gives you steps to create a notification hub in an existing namespace. You also learn how to create a custom access policy.
24+
25+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
26+
27+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
28+
29+
Notification Hubs requires version 2.0.67 or later of the Azure CLI. Run `az --version` to find the version and dependent libraries that are installed. To install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
30+
31+
## Prepare your environment
32+
33+
1. Sign in.
34+
35+
Sign in using the [az login](/cli/azure/reference-index#az-login) command if you're using a local install of the CLI.
36+
37+
```azurecli-interactive
38+
az login
39+
```
40+
41+
Follow the steps displayed in your terminal to complete the authentication process.
42+
43+
2. Install the Azure CLI extension.
44+
45+
To run the Azure CLI commands for notification hubs, install the Azure CLI [extension for Notification Hubs](/cli/azure/ext/notification-hub/notification-hub).
46+
47+
```azurecli-interactive
48+
az extension add --name notification-hub
49+
```
50+
51+
3. Create a resource group.
52+
53+
Azure notification hubs, like all Azure resources, must be deployed into a resource group. Resource groups allow you to organize and manage related Azure resources.
54+
55+
For this quickstart, create a resource group named *spnhubrg* in the *eastus* location with the following [az group create](/cli/azure/group#az-group-create) command:
56+
57+
```azurecli-interactive
58+
az group create --name spnhubrg --location eastus
59+
```
60+
61+
## Create a notification hub namespace
62+
63+
1. Create a namespace for your notification hubs
64+
65+
A namespace contains one or more hubs, and the name must be unique across all Azure subscriptions. To check the availability of the given service namespace, use the [az notification-hub namespace check-availability](/cli/azure/ext/notification-hub/notification-hub/namespace#ext-notification-hub-az-notification-hub-namespace-check-availability) command. Run the [az notification-hub namespace create](/cli/azure/ext/notification-hub/notification-hub/namespace#ext-notification-hub-az-notification-hub-namespace-create) command to create a namespace.
66+
67+
```azurecli-interactive
68+
#check availability
69+
az notification-hub namespace check-availability --name spnhubns
70+
71+
#create the namespace
72+
az notification-hub namespace create --resource-group spnhubrg --name spnhubns --location eastus --sku Free
73+
```
74+
75+
2. List keys and connection strings for your namespace access policy.
76+
77+
An access policy named **RootManageSharedAccessKey** is automatically created for a new namespace. Every access policy has two sets of keys and connection strings. To list the keys and connection strings for the namespace, run the [az notification-hub namespace authorization-rule list-keys](/cli/azure/ext/notification-hub/notification-hub/authorization-rule#ext-notification-hub-az-notification-hub-authorization-rule-list-keys) command.
78+
79+
```azurecli-interactive
80+
az notification-hub namespace authorization-rule list-keys --resource-group spnhubrg --namespace-name spnhubns --name RootManageSharedAccessKey
81+
```
82+
83+
## Create notification hubs
84+
85+
1. Create your first notification hub.
86+
87+
A notification hub can now be created in the new namespace. Run the [az notification-hub create](/cli/azure/ext/notification-hub/notification-hub#ext-notification-hub-az-notification-hub-create) command to create a notification hub.
88+
89+
```azurecli-interactive
90+
az notification-hub create --resource-group spnhubrg --namespace-name spnhubns --name spfcmtutorial1nhub --location eastus --sku Free
91+
```
92+
93+
2. Create a second notification hub.
94+
95+
Multiple notification hubs can be created in a single namespace. To create a second notification hub in the same namespace, run the `az notification-hub create` command again using a different hub name.
96+
97+
```azurecli-interactive
98+
az notification-hub create --resource-group spnhubrg --namespace-name spnhubns --name mysecondnhub --location eastus --sku Free
99+
```
100+
101+
## Work with access policies
102+
103+
1. Create a new authorization-rule for a notification hub.
104+
105+
An access policy is automatically created for each new notification hub. To create and customize your own access policy, use the [az notification-hub authorization-rule create](/cli/azure/ext/notification-hub/notification-hub/authorization-rule#ext-notification-hub-az-notification-hub-authorization-rule-create) command.
106+
107+
```azurecli-interactive
108+
az notification-hub authorization-rule create --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --name spnhub1key --rights Listen Send
109+
```
110+
111+
2. List access policies for a notification hub.
112+
113+
To query what access policies exist for a notification hub, use the [az notification-hub authorization-rule list](/cli/azure/ext/notification-hub/notification-hub/authorization-rule#ext-notification-hub-az-notification-hub-authorization-rule-list) command.
114+
115+
```azurecli-interactive
116+
az notification-hub authorization-rule list --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --output table
117+
```
118+
119+
> [!IMPORTANT]
120+
> Do not use the **DefaultFullSharedAccessSignature** policy in your application. This is meant to be used in your back-end only. Use only **Listen** access policies in your client application.
121+
122+
3. List keys and connection strings for a notification hub access policy
123+
124+
There are two sets of keys and connection strings for each access policy. You'll need them later to handle push notifications. To list the keys and connections strings for a notification hub access policy, use the [az notification-hub authorization-rule list-keys](/cli/azure/ext/notification-hub/notification-hub/authorization-rule#ext-notification-hub-az-notification-hub-authorization-rule-list-keys) command.
125+
126+
```azurecli-interactive
127+
#query the keys and connection strings for DefaultListenSharedAccessSignature
128+
az notification-hub authorization-rule list-keys --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --name DefaultListenSharedAccessSignature --output json
129+
130+
#query the keys and connection strings for the custom policy
131+
az notification-hub authorization-rule list-keys --resource-group spnhubrg --namespace-name spnhubns --notification-hub-name spfcmtutorial1nhub --name spnhub1key --output table
132+
```
133+
134+
> [!NOTE]
135+
> A [notification hub namespace](/cli/azure/ext/notification-hub/notification-hub/namespace/authorization-rule#ext-notification-hub-az-notification-hub-namespace-authorization-rule-list-keys) and a [notification hub](/cli/azure/ext/notification-hub/notification-hub/authorization-rule#ext-notification-hub-az-notification-hub-authorization-rule-list-keys) have separate access policies. Make sure you are using the correct Azure CLI reference when querying for keys and connection strings.
136+
137+
## Clean up resources
138+
139+
When no longer needed, use the [az group delete](/cli/azure/group) command to remove the resource group, and all related resources.
140+
141+
```azurecli-interactive
142+
az group delete --name spnhubrg
143+
```
144+
145+
## See also
146+
147+
Discover full capabilities for managing notifications hubs with the Azure CLI.
148+
149+
* [Notification Hubs full Azure CLI reference list](/cli/azure/ext/notification-hub/notification-hub)
150+
* [Notification Hubs namespace Azure CLI reference list](/cli/azure/ext/notification-hub/notification-hub/namespace)
151+
* [Notification Hubs authorization rule Azure CLI reference list](/cli/azure/ext/notification-hub/notification-hub/authorization-rule)
152+
* [Notification Hubs credential Azure CLI reference list](/cli/azure/ext/notification-hub/notification-hub/credential)

0 commit comments

Comments
 (0)