How to install managed dependency for example a Powershell module in Powershell based azure functions?

Bony Cherian 0 Reputation points
2024-04-18T07:59:03.2733333+00:00

In Azure function app, we are able to install Az modules as default as it mentions in the requiremnts.psd1 file as shown in the below image by uncommenting , it will install the Az module

User's image

By following the same process we are trying to install Microsoft.graph modules in the function app to use Microsoft graph commands in the scripts and followed the same process by mentioning it in the requirements.psd1 file as shown in the below imageUser's image

and also i tried different combinations in requirements .psd1 file as shown below

for example

@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    Az = '11.*'
    Microsoft.Graph = '2.15.0'
}
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    'Microsoft.Graph' = '2.15.0'
}

but it either fails or timeouts as shown below

User's image

User's image

and the only working one which we found is to upload the files manually into D:\home\site\wwwroot\Modules of the function and the commands worked as expected.

But the problem we face is to create a function app with Microsoft graph modules loaded automatically similar to how we can install Az modules in the function app by changing the contents of requirements.psd1 file instead of manually adding the function app by uploading the files.

**Can anyone please suggest why it does not install other modules but installs Az modules when mentioned in requirements.psd1 file but only works by uploading manually.**Thank You

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,285 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 25,821 Reputation points Microsoft Employee
    2024-04-22T16:41:46.1066667+00:00

    Hi @Bony Cherian

    Check your storage quota. If your running Consumption plan, installing Microsoft.Graph may be too large and you may not have enough disk space. You can change your plan to a Premium plan but you can't scale down to a dedicated plan if that's not option. Otherwise, you can recreate the function app with and associate to a dedicated app service plan to the SKU you want. If you don't want to go down that route, adjust your requirements.psd1 to include only the modules you need, rather than installing everything.

    As far as why uploading the module directly to the function app; it could be that requirements.psd1 saves module data to a temporary storage which is considerably smaller (especially on a Consumption plan). I've reached out the product group for more clarity on that premise and awaiting a response.


    EDIT 2024 Apr 23

    Reducing the number modules being installed to only what you need is the appropriate action. Module dependencies get downloaded to a temp folder which varies in size based on SKU. Once downloaded, the modules get extracted to ModuleDependenices which is mapped to the function's storage account. The Microsoft.Graph modules is ~890MB so based on SKU, you could run into space limitation issues. See https://github.com/Azure/azure-functions-powershell-worker/blob/dev/docs/designs/PowerShell-AzF-Overall-Design.md#problem for more details.

    0 comments No comments