Pre-download Azure Function modules

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.

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:

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!


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. 😄

Yoda Patience GIF - Yoda Patience You Must Have Patience GIFs