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-EC2Region : No difference between -Region and -RegionName parameters #46

Closed jrjespersen closed 4 years ago

jrjespersen commented 5 years ago

Get-EC2Region appears to have no different functionality between the -Region and -RegionName parameters.

Expected Behavior

-Region should declare which region to execute the API call against, but not filter the output (consistent with how the AWS CLI works for this command) -RegionName should filter the output of the API to the list of regions provided.

Current Behavior Both -Region and -RegionName parameters filter the output.

Steps to Reproduce (for bugs)

Import-Module AWSPowerShell.NetCore Set-DefaultAWSRegion us-east-1 Get-EC2Region -Region us-east-1 -ProfileName "AWS CORP LAB" #returns only us-east-1 Get-EC2Region -RegionName us-east-1 -ProfileName "AWS CORP LAB" #returns only us-east-1 aws ec2 describe-regions --region us-east-1 --profile "AWS CORP LAB" #returns all enabled regions

Context

We use Get-EC2Region because we do not enable all regions in all of our accounts, so for scripts which iterate over multiple accounts and regions, we must obtain which regions are active to avoid time-outs when attempting to make an API call to a disabled region.

Your Environment

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

jrjespersen commented 5 years ago

Additonally, I think this issue exists in the PowerShell implementation because I can execute the following snippet and get the expected results:

import-module awspowershell.netcore $cred = Get-AWSTemporaryCredential "AWS CORP LAB" #custom function to get temp creds $ec2 = new-object "Amazon.EC2.AmazonEC2Client"($cred,[Amazon.RegionEndPoint]::USEast1) $resp = $ec2.DescribeRegionsAsync((new-object "Amazon.EC2.Model.DescribeRegionsRequest")) $resp.result.regions

matteo-prosperi commented 5 years ago

Hello, thank you for reporting this. Could you try if

Get-EC2Region -RegionToCall us-east-1

solves your problem?

The Get-EC2Region cmdlets has two parameters (see here):

All the Common Credential and Region Parameters are dynamic parameters. Unfortunately PowerShell has an anomalous behavior where the parameter you specify binds with a higher priority to a static parameter prefix than to the full name of a dynamic parameter. So Region binds to RegionName instead of Region. This makes the Region parameter unusable unless you use the RegionToCall alias which works because it is not a prefix of a static parameter name. We are considering to change the Common Credential and Region Parameters to static parameters in the next release of AWS.Tools. We are hesitant to do the same in AWSPowerShell and AWSPowerShell.NetCore for backward compatibility concerns.

jrjespersen commented 5 years ago

Yes, this does provide an adequate solution for scripting. It's an annoyance for interactive use/development since it breaks splatting to this cmdlet using the same collection that I splat to every other cmdlet.

I support the change for AWS.Tools - I came across this issue in converting/updating/testing scripts in preparation for migration from AWSPowerShell/NetCore to AWS.Tools, so I'm less concerned with getting it fixed in AWSPowerShell/NetCore.

matteo-prosperi commented 4 years ago

Hello, as announced in https://github.com/aws/aws-tools-for-powershell/issues/61, we will change all parameters to static in the upcoming major version (v4). This change is already available in preview in the latest release of AWS.Tools. Thanks for reporting this issue.