0

There is a resource group with two important resource types: first one is a Container Instances (Linux). Second one is a Function App (Powershell, Windows). A function from the latter should start the former but it throws an error: Cannot bind argument to parameter 'InputObject' because it is null

What do I miss? The answer from this question gives the same error only when running within Function App, in Azure or in VSCode with Function Tools. When run in a terminal, the command Invoke-AzResourceAction works as it should.

Here is the function code:

# Input bindings are passed in via param block.
param($Timer)

# Get the current universal time in the default string format
$currentUTCtime = (Get-Date).ToUniversalTime()

# The 'IsPastDue' porperty is 'true' when the current function invocation is later than scheduled.
if ($Timer.IsPastDue) {
    Write-Host "PowerShell timer is running late!"
}

# Write an information log with the current time.
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime"

$cg = Get-AzContainerGroup -ResourceGroupName some-group-name -Name container-instance-name

Invoke-AzResourceAction -ResourceId $cg.Id `
    -Action start `
    -Force

Here is the output log:

Executing task: func host start

Azure Functions Core Tools Core Tools Version: 3.0.2996 Commit hash: c54cdc36323e9543ba11fb61dd107616e9022bba Function Runtime Version: 3.0.14916.0

Functions:

(function name): timerTrigger

For detailed output, run func with --verbose flag. Executing 'Functions.' (Reason='Timer fired at 2020-12-04T13:11:01.1496065+02:00', Id=c0b30df8-065d-4725-8fa7-22fdfad71a21) Trigger Details: UnscheduledInvocationReason: IsPastDue, OriginalSchedule: 2020-12-04T13:11:00.0000000+02:00 Worker process started and initialized. INFORMATION: PowerShell timer is running late! INFORMATION: PowerShell timer trigger function ran! TIME: 12/04/2020 11:11:06 INFORMATION: /subscriptions//resourceGroups//providers/Microsoft.ContainerInstance/containerGroups/ ERROR: Cannot bind argument to parameter 'InputObject' because it is null.

Exception : Type : System.Management.Automation.ParameterBindingValidationException
Message : Cannot bind argument to parameter 'InputObject' because it is null. ParameterName : InputObject ParameterType : System.Object ErrorId : ParameterArgumentValidationErrorNullNotAllowed CommandInvocation : MyCommand : Trace-PipelineObject HistoryId : 1 InvocationName : Microsoft.Azure.Functions.PowerShellWorker\Trace-PipelineObject PipelineLength : 2 PipelinePosition : 2 ExpectingInput : True ErrorRecord : Exception : Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Cannot bind argument to parameter 'InputObject' because it is null. HResult : -2146233087 CategoryInfo : InvalidData: (:) [Trace-PipelineObject], ParentContainsErrorRecordException FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Azure.Functions.PowerShellWorker.Commands.TracePipelineObjectCommand InvocationInfo : MyCommand : Trace-PipelineObject HistoryId : 1 CommandOrigin : Internal ScriptStackTrace : at , \orchestration<function name>\run.ps1: line 19
TargetSite : Name : BindValueFromPipeline DeclaringType : System.Management.Automation.CmdletParameterBinderController, System.Management.Automation, Version=7.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 MemberType : Method Module : System.Management.Automation.dll StackTrace : at System.Management.Automation.CmdletParameterBinderController.BindValueFromPipeline(PSObject inputToOperateOn, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags) at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingStateInParameterSet(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets) at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingState(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets) at System.Management.Automation.CmdletParameterBinderController.BindPipelineParametersPrivate(PSObject inputToOperateOn) at System.Management.Automation.CmdletParameterBinderController.BindPipelineParameters(PSObject inputToOperateOn) at System.Management.Automation.CommandProcessor.Read() Source : System.Management.Automation HResult : -2146233087 CategoryInfo : InvalidData: (:) [Trace-PipelineObject], ParameterBindingValidationException FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Azure.Functions.PowerShellWorker.Commands.TracePipelineObjectCommand InvocationInfo : MyCommand : Trace-PipelineObject HistoryId : 1 CommandOrigin : Internal ScriptStackTrace : at , \orchestration<function name>\run.ps1: line 19

Result: ERROR: Cannot bind argument to parameter 'InputObject' because it is null.

Exception : Type : System.Management.Automation.ParameterBindingValidationException Message : Cannot bind argument to parameter 'InputObject' because it is null. ParameterName : InputObject ParameterType : System.Object ErrorId : ParameterArgumentValidationErrorNullNotAllowed CommandInvocation : MyCommand : Trace-PipelineObject HistoryId : 1 InvocationName : Microsoft.Azure.Functions.PowerShellWorker\Trace-PipelineObject PipelineLength : 2 PipelinePosition : 2 ExpectingInput : True ErrorRecord : Exception : Type : System.Management.Automation.ParentContainsErrorRecordException Message : Cannot bind argument to parameter 'InputObject' because it is null. HResult : -2146233087 CategoryInfo : InvalidData: (:) [Trace-PipelineObject], ParentContainsErrorRecordException FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Azure.Functions.PowerShellWorker.Commands.TracePipelineObjectCommand InvocationInfo : MyCommand : Trace-PipelineObject HistoryId : 1 CommandOrigin : Internal ScriptStackTrace : at , <function name>\run.ps1: line 19
TargetSite : Name : BindValueFromPipeline DeclaringType : System.Management.Automation.CmdletParameterBinderController, System.Management.Automation, Version=7.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 MemberType : Method Module : System.Management.Automation.dll StackTrace : at System.Management.Automation.CmdletParameterBinderController.BindValueFromPipeline(PSObject inputToOperateOn, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags) at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingStateInParameterSet(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets) at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingState(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets) at System.Management.Automation.CmdletParameterBinderController.BindPipelineParametersPrivate(PSObject inputToOperateOn) at System.Management.Automation.CmdletParameterBinderController.BindPipelineParameters(PSObject inputToOperateOn) at System.Management.Automation.CommandProcessor.Read() Source : System.Management.Automation HResult : -2146233087 CategoryInfo : InvalidData: (:) [Trace-PipelineObject], ParameterBindingValidationException FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Azure.Functions.PowerShellWorker.Commands.TracePipelineObjectCommand InvocationInfo : MyCommand : Trace-PipelineObject HistoryId : 1 CommandOrigin : Internal ScriptStackTrace : at , \orchestration<function name>\run.ps1: line 19 Exception: Cannot bind argument to parameter 'InputObject' because it is null. Stack: at System.Management.Automation.CmdletParameterBinderController.BindValueFromPipeline(PSObject inputToOperateOn, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags) at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingStateInParameterSet(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets) at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingState(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets) at System.Management.Automation.CmdletParameterBinderController.BindPipelineParametersPrivate(PSObject inputToOperateOn) at System.Management.Automation.CmdletParameterBinderController.BindPipelineParameters(PSObject inputToOperateOn) at System.Management.Automation.CommandProcessor.Read(). Executed 'Functions.' (Succeeded, Id=c0b30df8-065d-4725-8fa7-22fdfad71a21, Duration=13327ms) Host lock lease acquired by instance ID '0000000000000000000000008ABBCF1E'.

1 Answer 1

2

Apparently, one of the commands in your script outputs $null, which hits this bug: https://github.com/Azure/azure-functions-powershell-worker/issues/561. Most likely, Invoke-AzResourceAction does that. The workaround is to redirect or capture the output, for example:

Invoke-AzResourceAction -ResourceId $cg.Id `
    -Action start `
    -Force | Out-Null

The bug has been recently fixed, but it will take a few weeks for the fix to be deployed to Azure.

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.