Skip to content

Can't import Az modules in AWS PowerShell Lambda #1085

@techthoughts2

Description

@techthoughts2

Description

AWS PowerShell Lambda does not currently permit the use of any cmdlets/functions from an Azure Az module.

Expectation

#Requires -Modules @{ModuleName='Az.Accounts';ModuleVersion='2.7.2'}

With an Az module added to a PowerShell Lambda - the module should be able to be successfully imported and functions engaged.

Actual Behavior

Importing module ./Modules/Az.Accounts/2.7.2/Az.Accounts.psd1
[Error] - Value cannot be null. (Parameter 'path1')

Reproduction Steps

  1. Add any Azure Az module to required modules for PowerShell Lambda:
    • #Requires -Modules @{ModuleName='Az.Accounts';ModuleVersion='2.7.2'}
  2. Deploy Lambda
  3. Attempt to run Lambda and observe import of Az module

Logs

When adding the Az module to the #Requires:

An exception was thrown when the constructor for type 'AzModuleProcessor.Bootstrap' was invoked. Check inner exception for more details.: LambdaException
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
Value cannot be null. (Parameter 'path1'): ArgumentNullException
   at Amazon.Lambda.PowerShellHost.PowerShellFunctionHost..ctor()
   at Amazon.Lambda.PowerShellHost.PowerShellFunctionHost..ctor(String powerShellScriptFileName)
   at AzModuleProcessor.Bootstrap..ctor() in /tmp/LambdaStaging/AzModuleProcessor/Bootstrap.cs:line 9

Importing module ./Modules/Az.Accounts/2.7.2/Az.Accounts.psd1
[Error] - Value cannot be null. (Parameter 'path1')

As a troubleshooting step I also attempted the following from within the Lambda logic code:

  • Use Save-Module and download an Az module directly from the PSGallery.
  • Perform a manual import within the Lambda using Import-Module. This also does not work and results in the following log entries:
2022-02-23T07:45:36.799-06:00	[Warning] - An error was encountered importing: Az.Accounts
2022-02-23T07:45:36.802-06:00   [Error] - Cannot bind argument to parameter 'Path' because it is an empty string.

Environment

  • Build Version: 7.0.8
  • OS Info: AWS PowerShell Lambda
  • Targeted .NET Platform: dotnetcore3.1 Lambda

Resolution

I think the issue is something with the System.IO.IsolatedStorage as that's the only place I see the "Path1" parameter.

Additional mentions of this issue


This is a 🐛 bug-report

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions