aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
238 stars 79 forks source link

Get-EC2Instance - Inconsistency in -Filter hashtable between actual and help #59

Closed pauby closed 4 years ago

pauby commented 4 years ago

The help examples for the Values key in the hashtable provided to the -Filter parameter and the actual required in the hashtable don't match.

Expected Behavior

The Get-Help Get-Ec2Instance -Examples command has this as one example:

-------------------------- EXAMPLE 3 --------------------------

PS C:\> (Get-EC2Instance -Filter @{Name="vpc-id";Value="vpc-1a2bc34d"},@{Name="subnet-id";Value="subnet-1a2b3c4d"}).Instances

Therefore, I should be able to use this:

Get-EC2Instance -Filter @{name="vpc-id"; value="=vpc-123456"}

Current Behavior

When I run the above I get an exception:

Get-EC2Instance : Cannot bind parameter 'Filter'. Cannot create object of type "Amazon.EC2.Model.Filter". The value property was not found for the Amazon.EC2.Model.Filter object. The available property is: [Name <System.String>] , [Values <System.Collections.Generic.List`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]>]
At line:1 char:25
+ Get-EC2Instance -Filter @{name="vpc-id"; value="=vpc-885aa3ec"}
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-EC2Instance], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Amazon.PowerShell.Cmdlets.EC2.GetEC2InstanceCmdlet

Possible Solution

The examples say that the key in the hashtable should be Value but the actual required key is Values. Following PowerShell best practice, it should really be Value that is used, which matches the help. However, that's unlikely to be practical for backwards compatibility. So updating the help is easier.

Your Environment

Include as many relevant details about the environment where the bug was discovered.

matteo-prosperi commented 4 years ago

Thanks for reporting this. We will fix this ASAP.

matteo-prosperi commented 4 years ago

The document page was updated with the corrected example: https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2Instance.html. Thanks for reporting this.

bcdady commented 4 years ago

I just encountered this same error message trying to pass a -Filter to the Get-EC2Tag cmdlet. What I think threw me off-track was that in the built-in EXAMPLE 5, the Filter Name field syntax is resource-type, but then in the cmdlet output, it shows ResourceId (not resource-id). Why are the taxonomy of the Filter and the return objects properties not consistent?

pauby commented 4 years ago

@bcdady This issue was closed as the documentation was resolved. Probably best to open a new issue for it.

matteo-prosperi commented 4 years ago

@bcdady Please open a separate issue if you want to discuss this. But we would not be able to change this behavior. As you can see here the behavior is inherited from the service protocol. The reason for the difference is probably due ResourceId being a "first class" property of the resource, not a tag. We can consider improving the documentation and the samples though, I created an issue to track this: https://github.com/aws/aws-tools-for-powershell/issues/131.