2

After installing azure-core-functions v3 and migrating a project to v3 Powershell projects began to fail. Narrowed down the issue to be that Az modules loaded as dependencies were no longer recognized at runtime. Further testing revealed the managed dependency setting in the functions host.json file is properly loading the Az modules as deleting the data/ManagedDependencies folder via Kudu and restarting the Function App restores the Az Modules, so requirements.psd1 is working - Powershell just cannot find the downloaded modules.

After reverting to v2 I find the same issue in v2. I was able to get around the issue temporarily by adding the required AZ modules to the modules folder in the Azure Function project. Note: Dev and Deploy is currently via VS Code.

How are Managed Dependencies referenced by Powershell? What are the next avenues to pursue to resolve the reference issues?

Host.json contents:

 "version": "2.0",
 "managedDependency": {
 "enabled": true
  }
}

requirements.psd1 contents:

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
 'Az' = '3.*'
}

Function App Config:

[
  {
    "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
    "value": "32178670-77eb-40aa-afbc-ca17946f0350",
    "slotSetting": false
  },
  {
    "name": "AzureWebJobsStorage",
    "value": "DefaultEndpointsProtocol=https;AccountName=REDACTED;EndpointSuffix=core.windows.net",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_EXTENSION_VERSION",
    "value": "~2",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_WORKER_RUNTIME",
    "value": "powershell",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
    "value": "DefaultEndpointsProtocol=REDACTED;EndpointSuffix=core.windows.net",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_CONTENTSHARE",
    "value": "rightrezmonitor7d0758",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_NODE_DEFAULT_VERSION",
    "value": "~10",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_RUN_FROM_PACKAGE",
    "value": "1",
    "slotSetting": false
  }
]

The data/ManagedDependencies/200103210646931.r directory in Kudu contains folders for AZ and AZ.Module folders

2
  • If you could share the failing code and the exact error message, this may be helpful. Commented Jan 24, 2020 at 1:34
  • If reverting from V3 to V2 does not help, my next guess would be that the problem was triggered not by the V2 to V3 switch, but by the Az modules upgrade. Please note that Az 3.3.0 was published on January 7, 2020, and your app automatically picked up that version. Please try to specify an older version (e.g. "3.2.0") instead of "3.*" in your requirements.psd1 and restart the app. If this solves the problem, something changed between Az 3.2.0 and 3.3.0, and this is the cause of the regression. Commented Jan 24, 2020 at 18:31

1 Answer 1

0

are you still seeing this issue? Does your function app have a dependency on .Net Core 2.2?

I have a PowerShell function app which uses the Get-AzKeyVaultSecret cmdlet to retrieve secrets from KeyVault. This function app was originally created to run on V2. However, I manually made the change to move it to V3, and everything continued to work as expected.

To answer your questions:

How are Managed Dependencies referenced by Powershell?

A: The managed dependencies path, which points to the storage account, is appended to $env:PSModulePath in the first invocation.

What are the next avenues to pursue to resolve the reference issues?

A: You could try force reinstalling the function app dependencies. To do so, go to the Portal and select your function app. Go to Overview and stop the function app. After that, select Platform features and go to Kudu as shown below.

enter image description here

Once in Kudu, go to Debug console, and select PowerShell as shown below.

enter image description here

From there, navigate to the D:\home\data\ManagedDependencies. Once there run Remove-Item * -Recurse -Force, e.g.,

cd D:\home\data\ManagedDependencies
Remove-Item * -Recurse -Force

Next, start the function app, and on the first function invocation, the dependencies will be downloaded and the path will be appended to $env:PSModulePath.

If you are still seeing issues after moving your app to V3, please open a issue at https://github.com/Azure/azure-functions-powershell-worker/issues, provide me with your function app name, and I will take a look.

Cheers,

Francisco

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.