繁体   English   中英

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

[英]Get Azure Storage Account Key inside Powershell Function App

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

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

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

Output:

<Subscription ID Hidden for Privacy>
stmobileplansstaging storageaccountrgmob83d8

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

Get-AzStorageAccountKey -ResourceGroupName rg-mobileplans -AccountName stmobileplansstaging

Output:

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 应用程序运行这些命令。 从 Powershell 运行它们有效。

我为 Function 应用程序创建了一个系统管理标识,并为其授予了对整个“rg-mobileplans”资源组和“stmobileplansstaging”存储帐户的“所有者”访问权限。

我错过了什么?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM