Skip to content

Commit a305192

Browse files
authored
Merge pull request #87686 from eamonoreilly/powershellmanageddependencies
Powershell managed dependencies
2 parents 6b6cd16 + 8e99c16 commit a305192

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

articles/azure-functions/functions-reference-powershell.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,18 @@ You can see the current version by printing `$PSVersionTable` from any function.
402402

403403
## Dependency management
404404

405-
PowerShell functions support managing Azure modules by the service. By modifying the host.json and setting the managedDependency enabled property to true, the requirements.psd1 file will be processed. The latest Azure modules will be automatically downloaded and made available to the function.
405+
PowerShell functions support downloading and managing [PowerShell gallery](https://www.powershellgallery.com) modules by the service. By modifying the host.json and setting the managedDependency enabled property to true, the requirements.psd1 file will be processed. The specified modules will be automatically downloaded and made available to the function.
406+
407+
The maximum number of modules currently supported is 10. The supported syntax is MajorNumber.* or exact module version as shown below. The Azure Az module is included by default when a new PowerShell function app is created.
408+
409+
The language worker will pick up any updated modules on a restart.
406410

407411
host.json
408412
```json
409413
{
410-
"managedDependency": {
411-
"enabled": true
412-
}
414+
"managedDependency": {
415+
"enabled": true
416+
}
413417
}
414418
```
415419

@@ -418,10 +422,11 @@ requirements.psd1
418422
```powershell
419423
@{
420424
Az = '1.*'
425+
SqlServer = '21.1.18147'
421426
}
422427
```
423428

424-
Leveraging your own custom modules or modules from the [PowerShell Gallery](https://powershellgallery.com) is a little different than how you would do it normally.
429+
Leveraging your own custom modules is a little different than how you would do it normally.
425430

426431
When you install the module on your local machine, it goes in one of the globally available folders in your `$env:PSModulePath`. Since your function runs in Azure, you won't have access to the modules installed on your machine. This requires that the `$env:PSModulePath` for a PowerShell function app differs from `$env:PSModulePath` in a regular PowerShell script.
427432

@@ -432,28 +437,32 @@ In Functions, `PSModulePath` contains two paths:
432437

433438
### Function app-level `Modules` folder
434439

435-
To use custom modules or PowerShell modules from the PowerShell Gallery, you can place modules on which your functions depend in a `Modules` folder. From this folder, modules are automatically available to the functions runtime. Any function in the function app can use these modules.
440+
To use custom modules, you can place modules on which your functions depend in a `Modules` folder. From this folder, modules are automatically available to the functions runtime. Any function in the function app can use these modules.
436441

437-
To take advantage of this feature, create a `Modules` folder in the root of your function app. Save the modules you want to use in your functions in this location.
442+
> [!NOTE]
443+
> Modules specified in the requirements.psd1 file are automatically downloaded and included in the path so you don't need to include them in the modules folder. These are stored locally in the $env:LOCALAPPDATA/AzureFunctions folder and in the /data/ManagedDependencies folder when run in the cloud.
444+
445+
To take advantage of the custom module feature, create a `Modules` folder in the root of your function app. Copy the modules you want to use in your functions to this location.
438446

439447
```powershell
440448
mkdir ./Modules
441-
Save-Module MyGalleryModule -Path ./Modules
449+
Copy-Item -Path /mymodules/mycustommodule -Destination ./Modules -Recurse
442450
```
443451

444-
Use `Save-Module` to save all of the modules your functions use, or copy your own custom modules to the `Modules` folder. With a Modules folder, your function app should have the following folder structure:
452+
With a Modules folder, your function app should have the following folder structure:
445453

446454
```
447455
PSFunctionApp
448456
| - MyFunction
449457
| | - run.ps1
450458
| | - function.json
451459
| - Modules
452-
| | - MyGalleryModule
453-
| | - MyOtherGalleryModule
454-
| | - MyCustomModule.psm1
460+
| | - MyCustomModule
461+
| | - MyOtherCustomModule
462+
| | - MySpecialModule.psm1
455463
| - local.settings.json
456464
| - host.json
465+
| - requirements.psd1
457466
```
458467

459468
When you start your function app, the PowerShell language worker adds this `Modules` folder to the `$env:PSModulePath` so that you can rely on module autoloading just as you would in a regular PowerShell script.
@@ -502,17 +511,7 @@ You set this environment variable in the [app settings](functions-app-settings.m
502511

503512
### Considerations for using concurrency
504513

505-
PowerShell is a _single threaded_ scripting language by default. However, concurrency can be added by using multiple PowerShell runspaces in the same process. This feature is how the Azure Functions PowerShell runtime works.
506-
507-
There are some drawbacks with this approach.
508-
509-
#### Concurrency is only as good as the machine it's running on
510-
511-
If your function app is running on an [App Service plan](functions-scale.md#app-service-plan) that only supports a single core, then concurrency won't help much. That's because there are no additional cores to help balance the load. In this case, performance can vary when the single core has to context-switch between runspaces.
512-
513-
The [Consumption plan](functions-scale.md#consumption-plan) runs using only one core, so you can't leverage concurrency. If you want to take full advantage of concurrency, instead deploy your functions to a function app running on a dedicated App Service plan with sufficient cores.
514-
515-
#### Azure PowerShell state
514+
PowerShell is a _single threaded_ scripting language by default. However, concurrency can be added by using multiple PowerShell runspaces in the same process. The amount of runspaces created will match the PSWorkerInProcConcurrencyUpperBound application setting. The throughput will be impacted by the amount of CPU and memory available in the selected plan.
516515

517516
Azure PowerShell uses some _process-level_ contexts and state to help save you from excess typing. However, if you turn on concurrency in your function app and invoke actions that change state, you could end up with race conditions. These race conditions are difficult to debug because one invocation relies on a certain state and the other invocation changed the state.
518517

0 commit comments

Comments
 (0)