Reputation: 4573
I'm using Azure Function 2.0 with Powershell and getting below error while installing Powershell modules.
Is there any way to get rid of this error. In general, we don't need admin rights to install NuGet/dependency.
I also tried with another way to put all Powershell modules under Modules folder
Still, function is not able to find Cosmos DB modules
Upvotes: 1
Views: 8640
Reputation: 1664
If the modules you want to use are on the PowerShell Gallery, the easiest way to use them from PowerShell Functions is to take advantage of the Managed Dependencies feature. All you need to do is to make sure you have the feature enabled in the host.json:
{
"managedDependency": {
"enabled": true
}
}
and your module is mentioned in the requirements.psd1:
@{
Az = '2.*'
SqlServer = '21.1.18147'
}
Azure Functions will automatically make sure these modules are installed and available to your functions. No need to copy files.
Please also note that AzureRM modules are not supported on Azure Functions v2.0, use Az instead.
Upvotes: 5
Reputation: 20067
You cannot simply call Import-Module Az.Profile
like on your local machine where you have previously installed Az.Profile
from that site. But you have to copy all files from that locally installed package into specific folder inside of your Function App in Azure.
1.Install Az.Profile
in local and go to its folder to get all the content in it.
2.Go to your function KUDU. Click CMD>site>wwwroot>yourFunctionName then create a directory called modules
.
3.Simply drag-and-drop
all files from your local powershell module location to your Azure Function App folder create above(modules
).
4.Include Az.Profile
PowerShell module in run.ps1
file like that example below:
Import-Module "D:\home\site\wwwroot\HttpTrigger1\modules\Az.Profile.psd1"
5.Install Az.Resources
and CosmosDB
module as above steps.
6.Run Get-CosmosDbOffer -Context $cosmosDbContext
and you will get the following snapshot.
For more details, you could refer to this tutorial and this one.
Upvotes: 1