Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-EC2Region : No difference between -Region and -RegionName parameters #46

Closed
jrjespersen opened this issue Aug 29, 2019 · 4 comments
Closed
Labels
backward incompatible bug This issue is a bug.

Comments

@jrjespersen
Copy link

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.

  • Affected module: AWSPowerShell.NetCore 3.3.563.1 and AWS.Tools.EC2 3.3.563.1
  • Operating System and version as reported by $PSVersionTable.OS: Darwin 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64
  • PowerShell version as reported by $PSVersionTable.PSEdition: Core (6.2.1)
@jrjespersen
Copy link
Author

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
Copy link
Contributor

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):

  • RegionName - a static parameter with a RegionNames alias,
  • Region - a dynamic parameter with a RegionToCall alias.

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
Copy link
Author

jrjespersen commented Sep 6, 2019

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
Copy link
Contributor

Hello, as announced in #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backward incompatible bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants