Sasa
Sasa

Reputation: 15

Install powershell modules for Azure Functions not working

I'm trying to use dependency feature (https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell#dependency-management) but i can't get them working. I added few module (O365, ITGlue modules etc.). I tried to restart function app after changing requirements.psd1 but still nothing. I don't see any error in logs regarding dependencies. What I'm missing here?

See requirements.psd1 file

Upvotes: 1

Views: 3747

Answers (1)

Bhargavi Annadevara
Bhargavi Annadevara

Reputation: 5512

The first check would be to ensure that managedDependency property is set to true in your function's host.json file:

{
  "managedDependency": {
          "enabled": true
       }
}

Restart the app after updating the requirements.psd1 file with the modules you need. You can notice the updates being processed in the logs:

Logs

If you want to verify the installation, you can go to the Kudu site for your app, and navigate to the path D:\home\data\ManagedDependencies\<id>\ and find them listed:

Kudu

Another simple way of verifying the same would be to tweak the function to list it. For example:

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
    $name = $Request.Body.Name
}

$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."

if ($name) {
    $body = "Hello, $name. This HTTP triggered function executed successfully."
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    # Body = $body
    Body = $(Get-Module -ListAvailable | Select-Object Name, Path)
})

Calling your function should now list all the installed dependencies: Example

Do note that Managed dependencies currently don't support modules that require the user to accept a license, either by accepting the license interactively, or by providing -AcceptLicense switch when invoking Install-Module. Also make sure that the runtime can access the PowerShell Gallery URL by adjusting any required firewall rules.

Upvotes: 1

Related Questions