在Powershell Function应用程序中获取Azure存储帐户密钥

时间:2020-07-15 18:18:13

标签: azure powershell azure-function-app azure-storage-account

我试图从Powershell Function应用程序内部的同一资源组“ rg-mobileplans”下获取存储帐户的密钥。

我确定我具有正确的Azure上下文,并且在列出所有存储帐户时,我看到了我正在尝试从中检索密钥的“ stmobileplansstaging”。

Write-Host ((Get-AzContext).Subscription)
Write-Host (Get-AzStorageAccount -ResourceGroupName rg-mobileplans).StorageAccountName

输出:

<Subscription ID Hidden for Privacy>
stmobileplansstaging storageaccountrgmob83d8

但是当我尝试自己获取密钥时,收到一条错误消息,提示找不到存储帐户。

Get-AzStorageAccountKey -ResourceGroupName rg-mobileplans -AccountName stmobileplansstaging

输出:

ERROR: Get-AzStorageAccountKey : The Resource 'Microsoft.Storage/storageAccounts/stmobileplansstaging ' under resource group 'rg-mobileplans' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix

请记住,我正在从Function App运行这些命令。从Powershell运行它们即可。

我已经为Function App创建了系统管理的身份,并授予其“所有者”访问整个“ rg-mobileplans”资源组和“ stmobileplansstaging”存储帐户的权限。

我想念什么?

1 个答案:

答案 0 :(得分:0)

我刚刚意识到问题出在哪里。在脚本中,存储帐户名称通过标签给出。名称末尾有一个空格。运行get / list storage account命令时,可以,命令成功,因为该帐户的名称可能在末尾,但是为了获取密钥,在POST调用下进行并且URL看起来像“ http:/ /.../storage/stmobileplansstaging / uri-rest-uri”。请注意,URI中间的空格破坏了所有内容。