{"id":7288,"date":"2023-07-29T11:46:47","date_gmt":"2023-07-29T10:46:47","guid":{"rendered":"https:\/\/rakhesh.com\/?p=7288"},"modified":"2023-07-29T11:46:47","modified_gmt":"2023-07-29T10:46:47","slug":"pre-download-azure-function-modules","status":"publish","type":"post","link":"https:\/\/rakhesh.com\/azure\/pre-download-azure-function-modules\/","title":{"rendered":"Pre-download Azure Function modules"},"content":{"rendered":"
Say I created a new Azure Function App and a Function within.<\/p>\n
I want to install a bunch of modules in it. Typically one would go to the App Files sections and edit Then restart the Function App.<\/p>\n If I were to run the Function App at this point it would get stuck like this:<\/p>\n <\/p>\n Eventually it times out coz it exceeds the 5 minute default timeout. And I have to keep trying until I finally get it working.<\/p>\n If you go to the Advanced Tools and launch Kudu:<\/p>\n <\/p>\n Then launch PowerShell:<\/p>\n <\/p>\n And go to <\/p>\n <\/p>\n <\/p>\n There’s folders like these:<\/p>\n <\/p>\n In my case the older folder had 68 items.<\/p>\n <\/p>\n The newer folder had 3 items.<\/p>\n Weirdly, the newer folder disappeared just as I was about to take a screenshot.<\/p>\n 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?<\/p>\n So is 68 items everything? Let’s download these locally to see how many items I have:<\/p>\n <\/p>\n The result of Can’t I just drag and drop these into that folder? That begins the upload process…<\/p>\n <\/p>\n … until I have everything uploaded:<\/p>\n <\/p>\n The difference in count is because Kudu has an additional file – Now can I run the Function? Yup, no errors!<\/p>\n <\/p>\n Sweet.<\/p>\n Later I realized there’s a better way.<\/p>\n I made a new Function App. Added the same module requirements & restarted. And went to the location in Kudu.<\/p>\n <\/p>\n Note, no I create a Function like before. That’s all. I didn’t even run it.<\/p>\n Notice a folder is created:<\/p>\n <\/p>\n It’s created a folder and started downloading too!<\/p>\n <\/p>\n <\/p>\n Jeez! So I didn’t even have to do all the stuff I did above.<\/p>\n All I have to do is wait.<\/p>\n I know the number of items there should be eventually – 84 module files + the requirements file. So I wait until that’s the count.<\/p>\n Takes a while… about 5 minutes.<\/p>\n <\/p>\n And now if I run the Function there’s no module downloads!<\/p>\n <\/p>\n Lesson learnt. \ud83d\ude04<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" 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. # This file enables modules to be automatically managed by the Functions service. # See https:\/\/aka.ms\/functionsmanageddependency for additional information. # @{ … Continue reading Pre-download Azure Function modules<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[887],"tags":[105,1110,227],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7288"}],"collection":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/comments?post=7288"}],"version-history":[{"count":1,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7288\/revisions"}],"predecessor-version":[{"id":7307,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7288\/revisions\/7307"}],"wp:attachment":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/media?parent=7288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/categories?post=7288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/tags?post=7288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}requirements.psd1<\/code>.<\/p>\n
# This file enables modules to be automatically managed by the Functions service.\r\n# See https:\/\/aka.ms\/functionsmanageddependency for additional information.\r\n#\r\n@{\r\n # For latest supported version, go to 'https:\/\/www.powershellgallery.com\/packages\/Az'. \r\n # To use the Az module in your function app, please uncomment the line below.\r\n 'Az' = '10.*'\r\n 'AzTable' = '2.*'\r\n 'ExchangeOnlineManagement' = '3.*'\r\n}\r\n<\/pre>\n
data<\/code> >
ManagedDependencies<\/code><\/p>\n
foreach ($module in \"Az\",\"AzTable\",\"ExchangeOnlineManagement\") {\r\n Find-Module \"$module\" | Save-Module -Path \"~\/Downloads\/modules\"\r\n}<\/pre>\n
(Get-ChildItem ~\/Downloads\/modules\/).Count<\/code> is 84 items. So we have a ways to go.<\/p>\n
requirements.psd1<\/code>.<\/p>\n
\nManagedDependencies<\/code> folder yet.<\/p>\n