Retrieve Service Bus primaryConnectionString with az cli
Asked Answered
L

2

6

Is it possible to get Azure Service Bus primaryConnectionString with AZ CLI?

Input parameters:

  1. Resource Group
  2. Service Bus Name
Locative answered 26/7, 2017 at 17:33 Comment(0)
L
20

Years later it's now supported. In case anyone else stumbles upon this question like me, it can be done this way:

az servicebus namespace authorization-rule keys list --resource-group myresourcegroup --namespace-name mynamespace --name RootManageSharedAccessKey --query primaryConnectionString -o tsv
Lombardi answered 12/10, 2020 at 17:47 Comment(0)
M
2

For now, Azure CLI 2.0 does not support service bus. You could use az -h to check. Power Shell and Azure CLI 1.0(asm mode) support service bus now.

You could use Power Shell to get primary ConnectionString.

$CurrentRule = Get-AzureRmServiceBusNamespaceAuthorizationRule -ResourceGroup $ResGrpName -NamespaceName $Namespace -AuthorizationRuleName $AuthRule
$AuthRule=$CurrentRule.Name
(Get-AzureRmServiceBusNamespaceKey -ResourceGroup shuibus -NamespaceName shuitest -AuthorizationRuleName $AuthRule).PrimaryConnectionString

More information please refer to this link.

Update:

On a Linux VM, you could use this Rest API to automation generate connectionstring.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceBus/namespaces/{namespaceName}/AuthorizationRules/{authorizationRuleName}/listKeys?api-version=2015-08-01
Monto answered 27/7, 2017 at 2:8 Comment(9)
Thanks. But I try to automate deployment scripts under linux. How to invoke Power Shell script with linux enviroment?Locative
@popalka For now, it is not possible.Monto
@popalka On Linux, you could use Rest API to get ConnectionString. learn.microsoft.com/en-us/rest/api/servicebus/…Monto
Thanks, I will tryLocative
@popalka You need create a service principle firstly. I test successful with Invoke-RestMethod. Now, I use curl for test, I will give you the result.Monto
@popalka The default authorizationRuleName name is RootManageSharedAccessKeyMonto
I didn't try yet. I stopped at creating service principle step. I'll try to keep this thread up-to date, thanksLocative
OK, if you any question about this. Please post here.Monto
As of October 2023, Shui's answer for REST API requires a tweak. The api version should be 2022-10-01-preview. So the full request URL becomes [ management.azure.com/subscriptions{subscriptionguid}/resourceGroups/{resourcegroup}/providers/Microsoft.ServiceBus/namespaces/{serviceBusNamespace}/AuthorizationRules/RootManageSharedAccessKey/listKeys?api-version=2022-10-01-preview ]Inordinate

© 2022 - 2024 — McMap. All rights reserved.