I am getting this error when trying to run my Azure Function (Which is in PowerShell). PowerShell script works normally when ran locally.
Error:
[Error] ERROR: No subscription found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Connect-AzAccount to login
In requirements.ps1
:
@{
'Az.Accounts' = '1.9.0'
'Az.Resources' = '1.1.2'
'AzTable' = '2.0.3'
'Az.Storage' = '1.7.0'
'Az.KeyVault' = '1.5.1'
}
In the run.ps1
, I added the Import-Module
commands:
Import-Module Az.Resources
Import-Module Az.Accounts
Import-Module Az.KeyVault
Import-Module AzTable
First few lines in 'run.ps1
':
$activeKey = Get-AzKeyVaultManagedStorageAccount -VaultName $keyVaultName -Name $storageAccountName
# Get Storage Account Key
$key = (Get-AzStorageAccountKey -ResourceGroupName $rgName -Name $storageAccountName)
In profile.ps1
:
if ($env:MSI_SECRET) {
Disable-AzContextAutosave
Connect-AzAccount -Identity
}
Thanks!
Please make sure you:
run.ps1
code, invoke Set-AzContext
to select the target subscription.Importing modules explicitly in run.ps1
is usually not necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With