Steps to Manually Add PowerShell Modules in Function App
Published Jun 09 2024 08:01 PM 1,432 Views
Microsoft

Function App lets you leverage PowerShell gallery for managing dependencies. Your PowerShell modules defined in requirements.psd1 file will be downloaded automatically if you enable dependency management. However, if your Function App runs on Consumption plan and the size of dependent modules is too large, chances are the download would fail. During the installation, the modules would be unziped and saved in the "D:\local\Temp", which is the temp storage on the plan worker. Due to the 500 MB limit of temp storage on consumption plan, the installation would fail with not enough space error:

 

System Log: { Log-Level: Warning; Log-Message: Save-Module('Microsoft.Graph', '2.18.0'): Package 'Microsoft.Graph.Files' failed to be installed because: There is not enough space on the disk. : 'C:\local\Temp\282636592\Microsoft.Graph.Files.2.18.0\bin\Microsoft.Graph.Files.private.dll' }

The easiest workaround is to scale up the function app plan to premium plan, as premium plan has much larger temp file size. However, this is not the most cost-saving option. You can install the module seperately to the app without depending on the dependency management feature either from local deployment or manual installation from the portal. Here I provide the steps with the second option to add the PowerShell modules directly using "Advanced Tools".

 

  1. Find and download modules from PowerShell Gallery to your local system. You should choose "manual download" and download the .nupkg files of the modules. 

    Raven_Zhang_8-1717932282759.png
  2. Unzip the .nupkg files and rename the folder to the module official name without the version number. 

    Raven_Zhang_9-1717932299585.png
  3. Open "App Service Editor" and create a new folder with name "Modules" under "wwwroot" folder. 

    Raven_Zhang_10-1717932312649.pngRaven_Zhang_11-1717932320969.png
  4. Go to SCM site of the Function App and navigate to "C:\home\site\wwwroot\Modules" path on the file system. 

    Raven_Zhang_12-1717932344685.pngRaven_Zhang_13-1717932351133.png
  5. Drag and drop the module package that you have downloaded before to the "Modules" folder on the SCM site.

  6. Go to "App Files", modify the "requirements.psd1" as the following, with the corresponding version number of the module: 

    Raven_Zhang_14-1717932370946.png
  7. In "host.json file", verify the managedDependency setting has a value of "Enabled" and is set to "False". 

    Raven_Zhang_15-1717932384982.png
  8. Restart the app, which is very important.

Now, you have successfully added the PowerShell modules to the Function App running on consumption plan, minus the "not enough space" error.

Co-Authors
Version history
Last update:
‎Jun 09 2024 08:01 PM
Updated by: