Say I created a new Azure Function App and a Function within.
I want to install a bunch of modules in it. Typically one would go to the App Files sections and edit requirements.psd1
.
1 2 3 4 5 6 7 8 9 10 |
# This file enables modules to be automatically managed by the Functions service. # See https://aka.ms/functionsmanageddependency for additional information. # @{ # 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' = '10.*' 'AzTable' = '2.*' 'ExchangeOnlineManagement' = '3.*' } |
Then restart the Function App.
If I were to run the Function App at this point it would get stuck like this:
Eventually it times out coz it exceeds the 5 minute default timeout. And I have to keep trying until I finally get it working.
If you go to the Advanced Tools and launch Kudu:
Then launch PowerShell:
And go to data
>ManagedDependencies
There’s folders like these:
In my case the older folder had 68 items.
The newer folder had 3 items.
Weirdly, the newer folder disappeared just as I was about to take a screenshot.
As you can see the folder contains the modules. So the Functions runtime downloads the modules to this location. When it times out the download stops, I suppose. Subsequent attempts start the process again to a fresh folder – which explains the folder I briefly saw? – and these too never complete until I get lucky?
So is 68 items everything? Let’s download these locally to see how many items I have:
1 2 3 |
foreach ($module in "Az","AzTable","ExchangeOnlineManagement") { Find-Module "$module" | Save-Module -Path "~/Downloads/modules" } |
The result of (Get-ChildItem ~/Downloads/modules/).Count
is 84 items. So we have a ways to go.
Can’t I just drag and drop these into that folder? That begins the upload process…
… until I have everything uploaded:
The difference in count is because Kudu has an additional file – requirements.psd1
.
Now can I run the Function? Yup, no errors!
Sweet.
Later I realized there’s a better way.
I made a new Function App. Added the same module requirements & restarted. And went to the location in Kudu.
Note, no ManagedDependencies
folder yet.
I create a Function like before. That’s all. I didn’t even run it.
Notice a folder is created:
It’s created a folder and started downloading too!
Jeez! So I didn’t even have to do all the stuff I did above.
All I have to do is wait.
I know the number of items there should be eventually – 84 module files + the requirements file. So I wait until that’s the count.
Takes a while… about 5 minutes.
And now if I run the Function there’s no module downloads!
Lesson learnt. 😄