AWS Developer Blog

Removal of Nullable Parameter Types in AWS Tools for Windows PowerShell

by Steve Roberts | on | in .NET* | Permalink | Comments |  Share

We wanted to let you know of a change to the Tools for Windows PowerShell, in which ‘nullable’ parameters used by some cmdlets will be removed. This affects some boolean, int, and DateTime parameters in a small number of cmdlets that up until now have been surfaced as Nullable<bool>, Nullable<int> or Nullable<DateTime> parameter types.

We’ve decided to make this change based on community feedback that nullable parameter types are not standard PowerShell practice and tend to confuse some beginners with the tools. In addition, specifying $null as the value to one of these parameters actually has no effect; the value is never passed onto the underlying service API call that the cmdlet makes, so surfacing nullable parameter types serves no useful purpose.

After the change, the parameters will become simple boolean, int and DateTime types. Note that this will only be a breaking change in your scripts if you have passed the value $null to one of these parameters. For example, you may have written:

PS C:> New-ASLaunchConfiguration -AssociatePublicIpAddress $null ...

If you look at the help for this cmdlet, it currently shows the AssociatePublicIpAddress parameter as being of type System.Boolean? (or, in other words, Nullable<bool>). Passing $null actually had no effect within the cmdlet; the parameter value was never passed onto the underlying service API call. After the update is released, your script will trigger an error if you use $null:

PS C:> New-ASLaunchConfiguration -AssociatePublicIpAddress $null ...

New-ASLaunchConfiguration : Cannot bind argument to parameter 'AssociatePublicIpAddress' because it is null.
At line:1 char:53
+ New-ASLaunchConfiguration -AssociatePublicIpAddress $null
+                                                     ~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-ASLaunchConfiguration], ParameterBindingException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Amazon.PowerShell.Cmdlets.AS.NewASLaunchConfigurationCmdlet

The fix is to simply remove the parameter; this is safe since, as noted above, the value was never used anyway. If your scripts pass actual values to these parameters (in this example, $true or $false), you won’t see any difference in behavior after the change is released.

The team would like to take this opportunity to give a shout-out to PowerShell MVP Jeff Wouters. Jeff has been taking the time to provide useful and actionable suggestions on the Tools for Windows PowerShell cmdlets since late last year, which we really appreciate.

If you have ideas about other changes we could make to the tools to enhance your scripting experience with AWS, then be sure to let us know!